123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- // pages/store/edit1.js
- const utils = require('../../utils/util')
- const form = require('../../utils/formValidation')
- const util = require('../../utils/util.js');
- const app = getApp();
- const chooseLocation = requirePlugin('chooseLocation');
- Page({
- // 从地图选点插件返回后,在页面的onShow生命周期函数中能够调用插件接口,取得选点结果对象
- onShow () {
- const location = chooseLocation.getLocation(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
- console.log(location)
- if(location!=null){
- console.log("")
- this.setData({
- ["storeInfo.storeAddress"]: location.name,
- ["storeInfo.latitude"]: location.latitude,
- ["storeInfo.longitude"]: location.longitude,
- });
- }
- },
- onUnload () {
- // 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
- chooseLocation.setLocation(null);
- },
- /**
- * 页面的初始数据
- */
- data: {
- selectList:[],
- multiArray: [], //picker数据
- value: [0, 0, 0],
- text: "",
- dictList:[],
- dataCityDictList:[],
- dadaTypeDictList:[],
- isPickerRender: false,
- isPickerShow: false,
- pickerConfig: {
- endDate: true,
- dateLimit: true,
- initStartTime: "2020-01-01",
- initEndTime: "2020-12-01",
- limitStartTime: "2015-01-01",
- limitEndTime: "2095-01-01"
- },
- values: {
- startTime: "2019-01-01 ",
- endTime: "2019-12-01"
- },
- storeInfo:{
- storeName: '',
- storePrincipal: '',
- storePrincipalPhone: '',
- storeTel: '',
- storeHouseNum: '',
- storeArea: '',
- storeAddress: '',
- businessBegin: '',
- businessEnd: '',
- },
- dataStr: '',
- storeId:'',
- region: [],
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- storeId: options.storeId
- })
- this.getChildListByMtLei();
- this.getDictByCode();
-
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- timePickerShow: function () {
- this.setData({
- isPickerShow: true,
- isPickerRender: true,
- chartHide: true
- });
- },
- pickerHide: function () {
- this.setData({
- isPickerShow: false,
- chartHide: false
- });
- },
- setPickerTime: function (val) {
- console.log(val);
- let data = val.detail;
- let startTime = utils.formatDate(data.startTime,'hh:mm')
- let endTime = utils.formatDate(data.endTime,'hh:mm')
- this.setData({
- ["values.startTime"]: startTime,
- ["values.endTime"]: endTime,
- dataStr: startTime +" ~ "+ endTime
- });
- this.data.storeInfo.businessBegin = this.data.values.startTime.replace(/\s+/g,"");
- this.data.storeInfo.businessEnd = this.data.values.endTime.replace(/\s+/g,"");
- },
- formSubmit: function(e) {
- //表单规则
- let rules = [{
- name: "storeName",
- rule: ["required"], //可使用区间,此处主要测试功能
- msg: ["请输入门店名称"]
- }, {
- name: "storePrincipal",
- rule: ["required", "isChinese", "minLength:2", "maxLength:6"],
- msg: ["请输入负责人姓名", "姓名必须全部为中文", "姓名必须2个或以上字符", "姓名不能超过6个字符"]
- },{
- name: "storePrincipalPhone",
- rule: ["required", "isMobile"],
- msg: ["请输入负责人手机号", "请输入正确的手机号"]
- }];
- var that = this
- if(!that.data.storeInfo.businessBegin||!that.data.storeInfo.businessEnd){
- util.toast("请输入营业时间")
- return;
- }
- if(!that.data.storeInfo.twoType){
- util.toast("请输入美团二级品类")
- return;
- }
- if(!that.data.storeInfo.dadaType){
- util.toast("请输入达达品类")
- return;
- }
-
- if(!that.data.storeInfo.dadaCityCode){
- util.toast("请输入达达配送城市")
- return;
- }
- if(!that.data.storeInfo.storeAddress){
- util.toast("请输入详细地址")
- return;
- }
- //进行表单检查
- let formData = e.detail.value;
- let checkRes = form.validation(formData, rules);
- if (!checkRes) {
- util.request(util.api.editStore, that.data.storeInfo, "PUT", false, true,app.globalData.token).then((res)=>{
- if (res.code == 200) {
- wx.navigateBack({
- url: '/pages/store/index',
- })
- console.log("========================")
- console.log(storeInfo)
- }
- }).catch((res) => {})
- // wx.showToast({
- // title: "验证通过!",
- // icon: "none"
- // });
- } else {
- wx.showToast({
- title: checkRes,
- icon: "none"
- });
- return;
- }
- },
- delete:function(){
-
- util.request(util.api.storeDelete,{id:this.data.storeId}, "DELETE", true, true,app.globalData.token).then((res)=>{
- if (res.code == 200) {
- wx.navigateTo({
- url: '/pages/store/index',
- })
- console.log("========================")
- console.log(storeInfo)
- }
- }).catch((res) => {})
- },
- formReset: function(e) {
- console.log("清空数据")
- },
- bindRegionChange: function (e) {
- console.log(e.detail.value)
- console.log(e.detail.code)
- this.setData({
- region: e.detail.value
- })
- this.data.storeInfo.storeArea = this.data.region.join(" ")
- },
- bindStore(){
- var that = this
- util.request(util.api.queryByStoreId, {id:that.data.storeId}, "GET", false, true,app.globalData.token).then((res)=>{
- if (res.code == 200) {
- var oneTypeData = that.data.selectList.filter((e)=>e.id == res.result.oneType );
- if(oneTypeData!=null&&oneTypeData.length>0){
- var twoTypeData = oneTypeData[0].children.filter((e)=>e.id == res.result.twoType );
- this.setData({
- text: oneTypeData[0].name + " " + twoTypeData[0].name ,
- })
- }
- that.setData({
- storeInfo: res.result,
- dataStr: res.result.businessBegin +" ~ "+ res.result.businessEnd,
- region: res.result.storeArea?(res.result.storeArea).split(" "):[]
- })
- var peisongTypeData = that.data.dictList.filter((e)=>e.value == res.result.peisongType );
- if(peisongTypeData !=null && peisongTypeData.length>0){
- that.setData({
- ['storeInfo.peisongTypeName']:peisongTypeData[0].text,
- })
- }
- var cityCodeData = that.data.dataCityDictList.filter((e)=>e.value == res.result.dadaCityCode );
- if(cityCodeData !=null && cityCodeData.length>0){
- that.setData({
- ['storeInfo.dadaCityName']:cityCodeData[0].text,
- })
- }
-
- var dadaTypeData = that.data.dadaTypeDictList.filter((e)=>e.value == res.result.dadaType );
- if(dadaTypeData !=null && dadaTypeData.length>0){
- that.setData({
- ['storeInfo.dadaTypeName']:dadaTypeData[0].text,
- })
- }
- console.log("========================")
- console.log(res.result)
- }
- }).catch((res) => {})
- },
- inputedit: function (e) {
- let _this = this;
- let dataset = e.currentTarget.dataset;
- let value = e.detail.value;
- let name = dataset.name;
- _this.data[name] = value;
- _this.setData({
- [name]: _this.data[name]
- });
- },
- //选择地图
- selectMap(){
- const key = '3UWBZ-YVSWX-V4245-T2G6T-QQ5US-BJFMP'; //使用在腾讯位置服务申请的key
- const referer = '梦果宝盒'; //调用插件的app的名称
- const location = JSON.stringify({
- latitude: 39.89631551,
- longitude: 116.323459711
- });
- const category = '生活服务,娱乐休闲';
-
- wx.navigateTo({
- url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}&category=${category}`
- });
- },
-
- picker: function(e) {
- let value = e.detail.value;
- if (this.data.selectList.length > 0) {
- let provice = this.data.selectList[value[0]].name
- let city = this.data.selectList[value[0]].children[value[1]].name
- this.setData({
- text: provice + " " + city ,
- ["storeInfo.twoType"]: this.data.selectList[value[0]].children[value[1]].id,
- ["storeInfo.oneType"]: this.data.selectList[value[0]].id
- })
- }
- },
- toArr(object) {
- let arr = [];
- for (let i in object) {
- arr.push(object[i].name);
- }
- return arr;
- },
- columnPicker: function(e) {
- console.log(2)
- //第几列 下标从0开始
- let column = e.detail.column;
- //第几行 下标从0开始
- let value = e.detail.value;
- if (column === 0) {
- this.setData({
- multiArray: [
- this.data.multiArray[0],
- this.toArr(this.data.selectList[value].children),
- // this.toArr(this.data.selectList[value].children[0].children)
- ],
- value: [value, 0, 0]
- })
- }
- },
- //获取美团品类
- getChildListByMtLei(){
- util.request(util.api.childListByMtLei, {}, "GET", false, true,app.globalData.token).then((res)=>{
- if (res.code == 200) {
- this.setData({
- selectList:res.result,
- multiArray: [
- this.toArr(res.result),
- this.toArr(res.result[0].children),
- ]
- })
- }else{
- util.toast("获取不到美团品类")
- }
- }).catch((res) => {})
- },
- //配送类型
- getDictByCode() {
- var that = this
- util.request(util.api.getDictByCode, {code:"peisong_type"}, "GET", false, true,app.globalData.token).then((res) => {
- if (res.code == 200) {
- that.setData({
- dictList: res.result
- })
- this.bindStore();
- }
- }).catch((res) => {})
- util.request(util.api.getDictByCode, {code:"dada_city"}, "GET", false, true,app.globalData.token).then((res) => {
- if (res.code == 200) {
- that.setData({
- dataCityDictList: res.result
- })
- }
- }).catch((res) => {})
- util.request(util.api.getDictByCode, {code:"dada_category"}, "GET", false, true,app.globalData.token).then((res) => {
- if (res.code == 200) {
- that.setData({
- dadaTypeDictList: res.result
- })
- }
- }).catch((res) => {})
-
- },
- //选配送类型
- bindDictPickerChange: function (e) {
- var item = this.data.dictList[e.detail.value]
- this.setData({
- ['storeInfo.peisongType']: item.value,
- ['storeInfo.peisongTypeName']: item.text
- })
- },
- //选达达配送城市
- bindDataCityDictPickerChange: function (e) {
- var item = this.data.dataCityDictList[e.detail.value]
- this.setData({
- ['storeInfo.dadaCityCode']: item.value,
- ['storeInfo.dadaCityName']: item.text
- })
- },
- //选达达品类
- bindDadaTypeDictPickerChange: function (e) {
- var item = this.data.dadaTypeDictList[e.detail.value]
- this.setData({
- ['storeInfo.dadaType']: item.value,
- ['storeInfo.dadaTypeName']: item.text
- })
- },
- })
|