edit.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. // pages/store/edit1.js
  2. const utils = require('../../utils/util')
  3. const form = require('../../utils/formValidation')
  4. const util = require('../../utils/util.js');
  5. const app = getApp();
  6. const chooseLocation = requirePlugin('chooseLocation');
  7. Page({
  8. // 从地图选点插件返回后,在页面的onShow生命周期函数中能够调用插件接口,取得选点结果对象
  9. onShow () {
  10. const location = chooseLocation.getLocation(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
  11. console.log(location)
  12. if(location!=null){
  13. console.log("")
  14. this.setData({
  15. ["storeInfo.storeAddress"]: location.name,
  16. ["storeInfo.latitude"]: location.latitude,
  17. ["storeInfo.longitude"]: location.longitude,
  18. });
  19. }
  20. },
  21. onUnload () {
  22. // 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
  23. chooseLocation.setLocation(null);
  24. },
  25. /**
  26. * 页面的初始数据
  27. */
  28. data: {
  29. isPickerRender: false,
  30. isPickerShow: false,
  31. pickerConfig: {
  32. endDate: true,
  33. dateLimit: true,
  34. initStartTime: "2020-01-01",
  35. initEndTime: "2020-12-01",
  36. limitStartTime: "2015-01-01",
  37. limitEndTime: "2095-01-01"
  38. },
  39. values: {
  40. startTime: "2019-01-01 ",
  41. endTime: "2019-12-01"
  42. },
  43. storeInfo:{
  44. storeName: '',
  45. storePrincipal: '',
  46. storePrincipalPhone: '',
  47. storeTel: '',
  48. storeHouseNum: '',
  49. storeArea: '',
  50. storeAddress: '',
  51. storeContractStart: '',
  52. storeContractEnd: '',
  53. },
  54. dataStr: '',
  55. storeId:'',
  56. region: [],
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad: function (options) {
  62. this.setData({
  63. storeId: options.storeId
  64. })
  65. this.bindStore()
  66. },
  67. /**
  68. * 生命周期函数--监听页面初次渲染完成
  69. */
  70. onReady: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面隐藏
  74. */
  75. onHide: function () {
  76. },
  77. /**
  78. * 页面相关事件处理函数--监听用户下拉动作
  79. */
  80. onPullDownRefresh: function () {
  81. },
  82. /**
  83. * 页面上拉触底事件的处理函数
  84. */
  85. onReachBottom: function () {
  86. },
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. onShareAppMessage: function () {
  91. },
  92. timePickerShow: function () {
  93. this.setData({
  94. isPickerShow: true,
  95. isPickerRender: true,
  96. chartHide: true
  97. });
  98. },
  99. pickerHide: function () {
  100. this.setData({
  101. isPickerShow: false,
  102. chartHide: false
  103. });
  104. },
  105. setPickerTime: function (val) {
  106. console.log(val);
  107. let data = val.detail;
  108. let startTime = utils.formatDate(data.startTime,'yyyy-MM-dd')
  109. let endTime = utils.formatDate(data.endTime,'yyyy-MM-dd')
  110. this.setData({
  111. ["values.startTime"]: data.startTime,
  112. ["values.endTime"]: data.endTime,
  113. dataStr: startTime +" ~ "+ endTime
  114. });
  115. this.data.storeInfo.storeContractStart = this.data.values.startTime;
  116. this.data.storeInfo.storeContractEnd = this.data.values.endTime;
  117. },
  118. formSubmit: function(e) {
  119. //表单规则
  120. let rules = [{
  121. name: "storeName",
  122. rule: ["required"], //可使用区间,此处主要测试功能
  123. msg: ["请输入门店名称"]
  124. }, {
  125. name: "storePrincipal",
  126. rule: ["required", "isChinese", "minLength:2", "maxLength:6"],
  127. msg: ["请输入负责人姓名", "姓名必须全部为中文", "姓名必须2个或以上字符", "姓名不能超过6个字符"]
  128. },{
  129. name: "storePrincipalPhone",
  130. rule: ["required", "isMobile"],
  131. msg: ["请输入负责人手机号", "请输入正确的手机号"]
  132. }];
  133. //进行表单检查
  134. let formData = e.detail.value;
  135. let checkRes = form.validation(formData, rules);
  136. if (!checkRes) {
  137. var that = this
  138. util.request(util.api.editStore, that.data.storeInfo, "PUT", false, true,app.globalData.token).then((res)=>{
  139. if (res.code == 200) {
  140. wx.navigateBack({
  141. url: '/pages/store/index',
  142. })
  143. console.log("========================")
  144. console.log(storeInfo)
  145. }
  146. }).catch((res) => {})
  147. // wx.showToast({
  148. // title: "验证通过!",
  149. // icon: "none"
  150. // });
  151. } else {
  152. wx.showToast({
  153. title: checkRes,
  154. icon: "none"
  155. });
  156. return;
  157. }
  158. },
  159. delete:function(){
  160. util.request(util.api.storeDelete,{id:this.data.storeId}, "DELETE", true, true,app.globalData.token).then((res)=>{
  161. if (res.code == 200) {
  162. wx.navigateTo({
  163. url: '/pages/store/index',
  164. })
  165. console.log("========================")
  166. console.log(storeInfo)
  167. }
  168. }).catch((res) => {})
  169. },
  170. formReset: function(e) {
  171. console.log("清空数据")
  172. },
  173. bindRegionChange: function (e) {
  174. console.log(e.detail.value)
  175. console.log(e.detail.code)
  176. this.setData({
  177. region: e.detail.value
  178. })
  179. this.data.storeInfo.storeArea = this.data.region.join("")
  180. },
  181. bindStore(){
  182. var that = this
  183. util.request(util.api.queryByStoreId, {id:that.data.storeId}, "GET", false, true,app.globalData.token).then((res)=>{
  184. if (res.code == 200) {
  185. that.setData({
  186. storeInfo: res.result,
  187. dataStr: res.result.storeContractStart +" ~ "+ res.result.storeContractEnd,
  188. region: (res.result.storeArea).split(" ")
  189. })
  190. console.log("========================")
  191. console.log(storeInfo)
  192. }
  193. }).catch((res) => {})
  194. },
  195. inputedit: function (e) {
  196. let _this = this;
  197. let dataset = e.currentTarget.dataset;
  198. let value = e.detail.value;
  199. let name = dataset.name;
  200. _this.data[name] = value;
  201. _this.setData({
  202. [name]: _this.data[name]
  203. });
  204. },
  205. //选择地图
  206. selectMap(){
  207. const key = '3UWBZ-YVSWX-V4245-T2G6T-QQ5US-BJFMP'; //使用在腾讯位置服务申请的key
  208. const referer = '梦果宝盒'; //调用插件的app的名称
  209. const location = JSON.stringify({
  210. latitude: 39.89631551,
  211. longitude: 116.323459711
  212. });
  213. const category = '生活服务,娱乐休闲';
  214. wx.navigateTo({
  215. url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}&category=${category}`
  216. });
  217. }
  218. })