add.js 7.3 KB

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