add.js 9.1 KB

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