edit.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. selectList:[],
  30. multiArray: [], //picker数据
  31. value: [0, 0, 0],
  32. text: "",
  33. isPickerRender: false,
  34. isPickerShow: false,
  35. pickerConfig: {
  36. endDate: true,
  37. dateLimit: true,
  38. initStartTime: "2020-01-01",
  39. initEndTime: "2020-12-01",
  40. limitStartTime: "2015-01-01",
  41. limitEndTime: "2095-01-01"
  42. },
  43. values: {
  44. startTime: "2019-01-01 ",
  45. endTime: "2019-12-01"
  46. },
  47. storeInfo:{
  48. storeName: '',
  49. storePrincipal: '',
  50. storePrincipalPhone: '',
  51. storeTel: '',
  52. storeHouseNum: '',
  53. storeArea: '',
  54. storeAddress: '',
  55. businessBegin: '',
  56. businessEnd: '',
  57. },
  58. dataStr: '',
  59. storeId:'',
  60. region: [],
  61. },
  62. /**
  63. * 生命周期函数--监听页面加载
  64. */
  65. onLoad: function (options) {
  66. this.setData({
  67. storeId: options.storeId
  68. })
  69. this.getChildListByMtLei()
  70. this.bindStore()
  71. },
  72. /**
  73. * 生命周期函数--监听页面初次渲染完成
  74. */
  75. onReady: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面隐藏
  79. */
  80. onHide: function () {
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh: function () {
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom: function () {
  91. },
  92. /**
  93. * 用户点击右上角分享
  94. */
  95. onShareAppMessage: function () {
  96. },
  97. timePickerShow: function () {
  98. this.setData({
  99. isPickerShow: true,
  100. isPickerRender: true,
  101. chartHide: true
  102. });
  103. },
  104. pickerHide: function () {
  105. this.setData({
  106. isPickerShow: false,
  107. chartHide: false
  108. });
  109. },
  110. setPickerTime: function (val) {
  111. console.log(val);
  112. let data = val.detail;
  113. let startTime = utils.formatDate(data.startTime,'hh:mm')
  114. let endTime = utils.formatDate(data.endTime,'hh:mm')
  115. this.setData({
  116. ["values.startTime"]: startTime,
  117. ["values.endTime"]: endTime,
  118. dataStr: startTime +" ~ "+ endTime
  119. });
  120. this.data.storeInfo.businessBegin = this.data.values.startTime.replace(/\s+/g,"");
  121. this.data.storeInfo.businessEnd = this.data.values.endTime.replace(/\s+/g,"");
  122. },
  123. formSubmit: function(e) {
  124. //表单规则
  125. let rules = [{
  126. name: "storeName",
  127. rule: ["required"], //可使用区间,此处主要测试功能
  128. msg: ["请输入门店名称"]
  129. }, {
  130. name: "storePrincipal",
  131. rule: ["required", "isChinese", "minLength:2", "maxLength:6"],
  132. msg: ["请输入负责人姓名", "姓名必须全部为中文", "姓名必须2个或以上字符", "姓名不能超过6个字符"]
  133. },{
  134. name: "storePrincipalPhone",
  135. rule: ["required", "isMobile"],
  136. msg: ["请输入负责人手机号", "请输入正确的手机号"]
  137. }];
  138. var that = this
  139. if(!that.data.storeInfo.businessBegin||!that.data.storeInfo.businessEnd){
  140. util.toast("请输入营业时间")
  141. return;
  142. }
  143. if(!that.data.storeInfo.twoType){
  144. util.toast("请输入二级品类")
  145. return;
  146. }
  147. if(!that.data.storeInfo.storeAddress){
  148. util.toast("请输入详细地址")
  149. return;
  150. }
  151. //进行表单检查
  152. let formData = e.detail.value;
  153. let checkRes = form.validation(formData, rules);
  154. if (!checkRes) {
  155. util.request(util.api.editStore, that.data.storeInfo, "PUT", false, true,app.globalData.token).then((res)=>{
  156. if (res.code == 200) {
  157. wx.navigateBack({
  158. url: '/pages/store/index',
  159. })
  160. console.log("========================")
  161. console.log(storeInfo)
  162. }
  163. }).catch((res) => {})
  164. // wx.showToast({
  165. // title: "验证通过!",
  166. // icon: "none"
  167. // });
  168. } else {
  169. wx.showToast({
  170. title: checkRes,
  171. icon: "none"
  172. });
  173. return;
  174. }
  175. },
  176. delete:function(){
  177. util.request(util.api.storeDelete,{id:this.data.storeId}, "DELETE", true, true,app.globalData.token).then((res)=>{
  178. if (res.code == 200) {
  179. wx.navigateTo({
  180. url: '/pages/store/index',
  181. })
  182. console.log("========================")
  183. console.log(storeInfo)
  184. }
  185. }).catch((res) => {})
  186. },
  187. formReset: function(e) {
  188. console.log("清空数据")
  189. },
  190. bindRegionChange: function (e) {
  191. console.log(e.detail.value)
  192. console.log(e.detail.code)
  193. this.setData({
  194. region: e.detail.value
  195. })
  196. this.data.storeInfo.storeArea = this.data.region.join("")
  197. },
  198. bindStore(){
  199. var that = this
  200. util.request(util.api.queryByStoreId, {id:that.data.storeId}, "GET", false, true,app.globalData.token).then((res)=>{
  201. if (res.code == 200) {
  202. var oneTypeData = that.data.selectList.filter((e)=>e.id == res.result.oneType );
  203. if(oneTypeData!=null&&oneTypeData.length>0){
  204. var twoTypeData = oneTypeData[0].children.filter((e)=>e.id == res.result.twoType );
  205. this.setData({
  206. text: oneTypeData[0].name + " " + twoTypeData[0].name ,
  207. })
  208. }
  209. console.log(66666)
  210. that.setData({
  211. storeInfo: res.result,
  212. dataStr: res.result.businessBegin +" ~ "+ res.result.businessEnd,
  213. region: (res.result.storeArea).split(" ")
  214. })
  215. console.log("========================")
  216. console.log(storeInfo)
  217. }
  218. }).catch((res) => {})
  219. },
  220. inputedit: function (e) {
  221. let _this = this;
  222. let dataset = e.currentTarget.dataset;
  223. let value = e.detail.value;
  224. let name = dataset.name;
  225. _this.data[name] = value;
  226. _this.setData({
  227. [name]: _this.data[name]
  228. });
  229. },
  230. //选择地图
  231. selectMap(){
  232. const key = '3UWBZ-YVSWX-V4245-T2G6T-QQ5US-BJFMP'; //使用在腾讯位置服务申请的key
  233. const referer = '梦果宝盒'; //调用插件的app的名称
  234. const location = JSON.stringify({
  235. latitude: 39.89631551,
  236. longitude: 116.323459711
  237. });
  238. const category = '生活服务,娱乐休闲';
  239. wx.navigateTo({
  240. url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}&category=${category}`
  241. });
  242. },
  243. picker: function(e) {
  244. let value = e.detail.value;
  245. if (this.data.selectList.length > 0) {
  246. let provice = this.data.selectList[value[0]].name
  247. let city = this.data.selectList[value[0]].children[value[1]].name
  248. this.setData({
  249. text: provice + " " + city ,
  250. ["storeInfo.twoType"]: this.data.selectList[value[0]].children[value[1]].id,
  251. ["storeInfo.oneType"]: this.data.selectList[value[0]].id
  252. })
  253. }
  254. },
  255. toArr(object) {
  256. let arr = [];
  257. for (let i in object) {
  258. arr.push(object[i].name);
  259. }
  260. return arr;
  261. },
  262. columnPicker: function(e) {
  263. console.log(2)
  264. //第几列 下标从0开始
  265. let column = e.detail.column;
  266. //第几行 下标从0开始
  267. let value = e.detail.value;
  268. if (column === 0) {
  269. this.setData({
  270. multiArray: [
  271. this.data.multiArray[0],
  272. this.toArr(this.data.selectList[value].children),
  273. // this.toArr(this.data.selectList[value].children[0].children)
  274. ],
  275. value: [value, 0, 0]
  276. })
  277. }
  278. },
  279. //获取美团品类
  280. getChildListByMtLei(){
  281. util.request(util.api.childListByMtLei, {}, "GET", false, true,app.globalData.token).then((res)=>{
  282. if (res.code == 200) {
  283. this.setData({
  284. selectList:res.result,
  285. multiArray: [
  286. this.toArr(res.result),
  287. this.toArr(res.result[0].children),
  288. ]
  289. })
  290. }else{
  291. util.toast("获取不到美团品类")
  292. }
  293. }).catch((res) => {})
  294. }
  295. })