edit.js 11 KB

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