edit.js 9.4 KB

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