add.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. const utils = require('../../utils/util')
  2. const form = require('../../utils/formValidation')
  3. const util = require('../../utils/util.js');
  4. const app = getApp();
  5. const chooseLocation = requirePlugin('chooseLocation');
  6. Page({
  7. // 从地图选点插件返回后,在页面的onShow生命周期函数中能够调用插件接口,取得选点结果对象
  8. onShow () {
  9. const location = chooseLocation.getLocation(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
  10. console.log(location)
  11. if(location!=null){
  12. console.log("")
  13. this.setData({
  14. ["storeInfo.storeAddress"]: location.name,
  15. ["storeInfo.latitude"]: location.latitude,
  16. ["storeInfo.longitude"]: location.longitude,
  17. });
  18. }
  19. },
  20. onUnload () {
  21. // 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
  22. chooseLocation.setLocation(null);
  23. },
  24. /**
  25. * 页面的初始数据
  26. */
  27. data: {
  28. selectList:[],
  29. multiArray: [], //picker数据
  30. value: [0, 0, 0],
  31. text: "",
  32. dictList:[],
  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. region: [],
  60. },
  61. /**
  62. * 生命周期函数--监听页面加载
  63. */
  64. onLoad: function (options) {
  65. this.getChildListByMtLei()
  66. this.getDictByCode();
  67. },
  68. /**
  69. * 生命周期函数--监听页面初次渲染完成
  70. */
  71. onReady: function () {
  72. },
  73. /**
  74. * 生命周期函数--监听页面隐藏
  75. */
  76. onHide: function () {
  77. },
  78. /**
  79. * 页面相关事件处理函数--监听用户下拉动作
  80. */
  81. onPullDownRefresh: function () {
  82. },
  83. /**
  84. * 页面上拉触底事件的处理函数
  85. */
  86. onReachBottom: function () {
  87. },
  88. /**
  89. * 用户点击右上角分享
  90. */
  91. onShareAppMessage: function () {
  92. },
  93. timePickerShow: function () {
  94. this.setData({
  95. isPickerShow: true,
  96. isPickerRender: true,
  97. chartHide: true
  98. });
  99. },
  100. pickerHide: function () {
  101. this.setData({
  102. isPickerShow: false,
  103. chartHide: false
  104. });
  105. },
  106. setPickerTime: function (val) {
  107. console.log(val);
  108. let data = val.detail;
  109. let startTime = utils.formatDate(data.startTime,'hh:mm')
  110. let endTime = utils.formatDate(data.endTime,'hh:mm')
  111. console.log(startTime)
  112. console.log(endTime)
  113. this.setData({
  114. ["values.startTime"]: startTime,
  115. ["values.endTime"]: endTime,
  116. dataStr: startTime +" ~ "+ endTime
  117. });
  118. this.data.storeInfo.businessBegin = this.data.values.startTime.replace(/\s+/g,"");
  119. this.data.storeInfo.businessEnd = this.data.values.endTime.replace(/\s+/g,"");
  120. },
  121. formSubmit: function(e) {
  122. //表单规则
  123. let rules = [{
  124. name: "storeName",
  125. rule: ["required"], //可使用区间,此处主要测试功能
  126. msg: ["请输入门店名称"]
  127. }, {
  128. name: "storePrincipal",
  129. rule: ["required", "isChinese", "minLength:2", "maxLength:6"],
  130. msg: ["请输入负责人姓名", "姓名必须全部为中文", "姓名必须2个或以上字符", "姓名不能超过6个字符"]
  131. },{
  132. name: "storePrincipalPhone",
  133. rule: ["required", "isMobile"],
  134. msg: ["请输入负责人手机号", "请输入正确的手机号"]
  135. },{
  136. name: "storeDivide",
  137. rule: ["required"],
  138. msg: ["请输入门店分成"]
  139. },{
  140. name: "mtType",
  141. rule: ["required"],
  142. msg: ["请输入二级品类"]
  143. }
  144. ];
  145. var that = this
  146. if(!that.data.storeInfo.businessBegin||!that.data.storeInfo.businessEnd){
  147. util.toast("请输入营业时间")
  148. return;
  149. }
  150. if(!that.data.storeInfo.twoType){
  151. util.toast("请输入二级品类")
  152. return;
  153. }
  154. if(!that.data.storeInfo.storeAddress){
  155. util.toast("请输入详细地址")
  156. return;
  157. }
  158. //进行表单检查
  159. let formData = e.detail.value;
  160. let checkRes = form.validation(formData, rules);
  161. if (!checkRes) {
  162. util.request(util.api.addStore, that.data.storeInfo, "POST", false, true,app.globalData.token).then((res)=>{
  163. if (res.code == 200) {
  164. wx.navigateTo({
  165. url: '/pages/store/index',
  166. })
  167. }else{
  168. util.toast("该门店名称已存在,请重新输入")
  169. }
  170. }).catch((res) => {})
  171. } else {
  172. wx.showToast({
  173. title: checkRes,
  174. icon: "none"
  175. });
  176. }
  177. },
  178. formReset: function(e) {
  179. console.log("清空数据")
  180. },
  181. bindRegionChange: function (e) {
  182. console.log(e.detail.value)
  183. console.log(e.detail.code)
  184. this.setData({
  185. region: e.detail.value
  186. })
  187. this.data.storeInfo.storeArea = this.data.region.join(" ")
  188. },
  189. inputedit: function (e) {
  190. let _this = this;
  191. let dataset = e.currentTarget.dataset;
  192. let value = e.detail.value;
  193. let name = dataset.name;
  194. _this.data[name] = value;
  195. _this.setData({
  196. [name]: _this.data[name]
  197. });
  198. },
  199. //选择地图
  200. selectMap(){
  201. const key = '3UWBZ-YVSWX-V4245-T2G6T-QQ5US-BJFMP'; //使用在腾讯位置服务申请的key
  202. const referer = '梦果宝盒'; //调用插件的app的名称
  203. const location = JSON.stringify({
  204. latitude: 39.89631551,
  205. longitude: 116.323459711
  206. });
  207. const category = '生活服务,娱乐休闲';
  208. wx.navigateTo({
  209. url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}&category=${category}`
  210. });
  211. },
  212. picker: function(e) {
  213. let value = e.detail.value;
  214. if (this.data.selectList.length > 0) {
  215. let provice = this.data.selectList[value[0]].name
  216. let city = this.data.selectList[value[0]].children[value[1]].name
  217. this.setData({
  218. text: provice + " " + city ,
  219. ["storeInfo.twoType"]: this.data.selectList[value[0]].children[value[1]].id,
  220. ["storeInfo.oneType"]: this.data.selectList[value[0]].id
  221. })
  222. }
  223. },
  224. toArr(object) {
  225. let arr = [];
  226. for (let i in object) {
  227. arr.push(object[i].name);
  228. }
  229. return arr;
  230. },
  231. columnPicker: function(e) {
  232. console.log(2)
  233. //第几列 下标从0开始
  234. let column = e.detail.column;
  235. //第几行 下标从0开始
  236. let value = e.detail.value;
  237. if (column === 0) {
  238. this.setData({
  239. multiArray: [
  240. this.data.multiArray[0],
  241. this.toArr(this.data.selectList[value].children),
  242. // this.toArr(this.data.selectList[value].children[0].children)
  243. ],
  244. value: [value, 0, 0]
  245. })
  246. }
  247. },
  248. //获取美团品类
  249. getChildListByMtLei(){
  250. util.request(util.api.childListByMtLei, {}, "GET", false, true,app.globalData.token).then((res)=>{
  251. if (res.code == 200) {
  252. this.setData({
  253. selectList:res.result,
  254. multiArray: [
  255. this.toArr(res.result),
  256. this.toArr(res.result[0].children),
  257. ]
  258. })
  259. }else{
  260. util.toast("获取不到美团品类")
  261. }
  262. }).catch((res) => {})
  263. },
  264. //配送类型
  265. getDictByCode() {
  266. var that = this
  267. util.request(util.api.getDictByCode, {code:"peisong_type"}, "GET", false, true,app.globalData.token).then((res) => {
  268. if (res.code == 200) {
  269. that.setData({
  270. dictList: res.result
  271. })
  272. }
  273. }).catch((res) => {})
  274. },
  275. //选配送类型
  276. bindDictPickerChange: function (e) {
  277. var item = this.data.dictList[e.detail.value]
  278. this.setData({
  279. ['storeInfo.peisongType']: item.value,
  280. ['storeInfo.peisongTypeName']: item.text
  281. })
  282. },
  283. })