|
|
@@ -1,23 +1,282 @@
|
|
|
-// pages/productManagement/change.js
|
|
|
-Component({
|
|
|
+import {
|
|
|
+ ApiModel
|
|
|
+} from "../../utils/api";
|
|
|
+const _Http = new ApiModel();
|
|
|
+import {
|
|
|
+ TestVerify
|
|
|
+} from "../../utils/verify";
|
|
|
+const _Verify = new TestVerify();
|
|
|
+Page({
|
|
|
+
|
|
|
/**
|
|
|
- * 组件的属性列表
|
|
|
+ * 页面的初始数据
|
|
|
*/
|
|
|
- properties: {
|
|
|
+ data: {
|
|
|
+ fprodname: "", //产品名称
|
|
|
+ fprodnum: "", //产品编码
|
|
|
+ attinfos: [], //附件列表
|
|
|
+ fintroduction: "", //产品说明
|
|
|
+ ftag: [], //产品标签
|
|
|
+ showSaleprod: "", //标签显示
|
|
|
+ tagents_productid: 0, //识别产品ID
|
|
|
+ checked: false, //开关控件
|
|
|
+ newAdd: false, //新增标识,新增时true,在保存后会更改为false 如果退出页面仍为true 改产品会被删除
|
|
|
+ errTips: {
|
|
|
+ fprodname: false,
|
|
|
+ fprodnum: false,
|
|
|
+ showSaleprod: false,
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onLoad: function (options) {
|
|
|
+ if (options.data) {
|
|
|
+ const data = JSON.parse(options.data)
|
|
|
+ let imageList = []
|
|
|
+ console.log(data)
|
|
|
+ /* 格式化图片列表 */
|
|
|
+ for (let i = 0; i < data.attinfos.length; i++) {
|
|
|
+ let obj = {
|
|
|
+ url: data.attinfos[i].fobsurl,
|
|
|
+ ownerid: data.attinfos[i].ownerid,
|
|
|
+ tattachmentid: data.attinfos[i].tattachmentid
|
|
|
+ }
|
|
|
+ imageList.push(obj)
|
|
|
+ };
|
|
|
+ /* 是否上架 */
|
|
|
+ if (data.fisonsale == 1) {
|
|
|
+ this.setData({
|
|
|
+ checked: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ let showSaleprod = "",
|
|
|
+ ftag = data.ftag
|
|
|
+ /* 空标签转换为数组格式 */
|
|
|
+ if (data.ftag == null || data.ftag == '') {
|
|
|
+ console.log(21)
|
|
|
+ ftag = []
|
|
|
+ } else {
|
|
|
+ /* 字符串数组转换数组 */
|
|
|
+ for (var i = 0; i < ftag.length; i++) {
|
|
|
+ showSaleprod += ftag[i] + ' ';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 渲染数据 */
|
|
|
+ this.setData({
|
|
|
+ fprodname: data.fprodname, //产品名称
|
|
|
+ fprodnum: data.fprodnum, //产品编码
|
|
|
+ attinfos: imageList, //附件列表
|
|
|
+ fintroduction: data.fintroduction, //产品说明
|
|
|
+ fisonsale: data.fisonsale, //是否上架
|
|
|
+ ftag: ftag, //产品标签
|
|
|
+ tagents_productid: data.tagents_productid, //识别产品ID
|
|
|
+ showSaleprod, // 显示标签
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ //新增产品,先新建一个产品,未保存退出页面会删除
|
|
|
+ this.submit();
|
|
|
+ this.setData({
|
|
|
+ newAdd: true
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * 组件的初始数据
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
- data: {
|
|
|
+ onReady: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+ /* 上架开关 */
|
|
|
+ switchChange() {
|
|
|
+ const checked = !this.data.checked;
|
|
|
+ this.setData({
|
|
|
+ checked
|
|
|
+ });
|
|
|
+ const fisonsale = (checked) ? 1 : 0;
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "customer.products.products",
|
|
|
+ "method": "updatesalestatus",
|
|
|
+ "content": {
|
|
|
+ "productlist": [{
|
|
|
+ "tagents_productid": this.data.tagents_productid,
|
|
|
+ "fisonsale": fisonsale
|
|
|
+ }]
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ if (res.msg != "成功") return wx.showToast({
|
|
|
+ title: res.data,
|
|
|
+ icon: "error"
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 表单验证 */
|
|
|
+ formVerify() {
|
|
|
+ let errTips = this.data.errTips,
|
|
|
+ verify = true;
|
|
|
+ /* 验证产品名称 */
|
|
|
+ if (!_Verify.required(this.data.fprodname)) {
|
|
|
+ errTips.fprodname = true;
|
|
|
+ verify = false;
|
|
|
+ }
|
|
|
+ /* 验证产品编码 */
|
|
|
+ if (!_Verify.required(this.data.fprodnum)) {
|
|
|
+ errTips.fprodnum = true;
|
|
|
+ verify = false;
|
|
|
+ }
|
|
|
+ /* 验证附件列表 */
|
|
|
+ if (!_Verify.required(this.data.attinfos, "请上传产品图片")) {
|
|
|
+ errTips.fprodnum = true;
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ errTips
|
|
|
+ })
|
|
|
+ return verify;
|
|
|
+ },
|
|
|
+ /* 提交 */
|
|
|
+ submit() {
|
|
|
+ if (!this.formVerify()) return;
|
|
|
+ let content = {};
|
|
|
+ //请求参数
|
|
|
+ if (this.data.tagents_productid != 0) {
|
|
|
+ content = {
|
|
|
+ "tagents_productid": this.data.tagents_productid,
|
|
|
+ "fprodnum": this.data.fprodnum,
|
|
|
+ "fprodname": this.data.fprodname,
|
|
|
+ "fintroduction": this.data.fintroduction,
|
|
|
+ "ftag": this.data.ftag,
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ content = {
|
|
|
+ "tagents_productid": 0
|
|
|
+ }
|
|
|
+ };
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "customer.products.products",
|
|
|
+ "method": "insertOrModifyProducts",
|
|
|
+ "content": content
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ if (res.msg == "成功") {
|
|
|
+ if (this.data.tagents_productid != 0) {
|
|
|
+ //非新增项目
|
|
|
+ wx.showToast({
|
|
|
+ title: '保存成功',
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ newAdd: false
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.navigateBack({
|
|
|
+ delta: 1,
|
|
|
+ })
|
|
|
+ }, 500)
|
|
|
+ } else {
|
|
|
+ //新增未保存项目
|
|
|
+ this.setData({
|
|
|
+ tagents_productid: res.data[0].tagents_productid
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 获取焦点 */
|
|
|
+ inputFocus(e) {
|
|
|
+ const {
|
|
|
+ name
|
|
|
+ } = e.currentTarget.dataset;
|
|
|
+ let errTips = this.data.errTips;
|
|
|
+ errTips[name] = false;
|
|
|
+ /* 经营类目提示框 */
|
|
|
+ if (name == 'showSaleprod') {
|
|
|
+ errTips[name] = true;
|
|
|
+ console.log(23)
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ errTips
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 失去焦点 */
|
|
|
+ inputBlur(e) {
|
|
|
+ const {
|
|
|
+ name
|
|
|
+ } = e.currentTarget.dataset;
|
|
|
+ const {
|
|
|
+ value
|
|
|
+ } = e.detail;
|
|
|
+ /* 经营类目提示框,字符串转化数组 */
|
|
|
+ if (name == 'showSaleprod') {
|
|
|
+ let errTips = this.data.errTips;
|
|
|
+ const ftag = this.data.showSaleprod.split(" ");
|
|
|
+ errTips[name] = false;
|
|
|
+ this.setData({
|
|
|
+ ftag,
|
|
|
+ errTips
|
|
|
+ })
|
|
|
+ };
|
|
|
+ if (value.trim() == "") {
|
|
|
+ let errTips = this.data.errTips;
|
|
|
+ errTips[name] = true;
|
|
|
+ this.setData({
|
|
|
+ errTips
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload: function () {
|
|
|
+ if (this.data.newAdd) {
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "customer.products.products",
|
|
|
+ "method": "deleteProducts",
|
|
|
+ "content": {
|
|
|
+ "tagents_productid": this.data.tagents_productid
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ onReachBottom: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * 组件的方法列表
|
|
|
+ * 用户点击右上角分享
|
|
|
*/
|
|
|
- methods: {
|
|
|
+ onShareAppMessage: function () {
|
|
|
|
|
|
}
|
|
|
-})
|
|
|
+})
|