change.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. import {
  6. TestVerify
  7. } from "../../utils/verify";
  8. const _Verify = new TestVerify();
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. fprodname: "", //产品名称
  15. fprodnum: "", //产品编码
  16. attinfos: [], //附件列表
  17. categoryListings: [], //类别列表
  18. fintroduction: "", //产品说明
  19. //ftag: [],产品标签
  20. showSaleprod: "", //标签显示
  21. tagents_productid: 0, //识别产品ID
  22. checked: true, //开关控件
  23. fisonsale: 1, //是否上架
  24. throttle: false, //保存节流阀
  25. errTips: {
  26. fprodname: false,
  27. fprodnum: false,
  28. showSaleprod: false,
  29. fprodclassname: false
  30. },
  31. fprodclassname: "", //产品分类
  32. pupShow: false, //弹出层控制
  33. },
  34. selection() {
  35. this.setData({
  36. pupShow: !this.data.pupShow
  37. })
  38. },
  39. /* input事件剔除特殊字符 */
  40. eliminate(value) {
  41. const {
  42. name
  43. } = value.target.dataset;
  44. this.setData({
  45. [name]: _Verify.Eliminate(value.detail)
  46. })
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad: function (options) {
  52. console.log(options.data)
  53. if (options.data) {
  54. const data = JSON.parse(options.data);
  55. console.log(data)
  56. let attinfos = [];
  57. for (let i = 0; i < data.attinfos.length; i++) {
  58. let arr = {
  59. url: data.attinfos[i].fobsurl,
  60. ownerid: data.attinfos[i].ownerid,
  61. tattachmentid: data.attinfos[i].tattachmentid,
  62. ownertable: data.attinfos[i].ownertable,
  63. fdocument: data.attinfos[i].fdocument,
  64. fprodclassname: data.attinfos[i].fprodclassname
  65. }
  66. attinfos.push(arr)
  67. };
  68. /* 是否上架 */
  69. const checked = (data.fisonsale == 1) ? true : false
  70. let showSaleprod = "";
  71. /* 空标签转换为数组格式
  72. ftag = data.ftag
  73. if (data.ftag == null || data.ftag == '') {
  74. ftag = []
  75. } else {
  76. //字符串数组转换数组
  77. for (var i = 0; i < ftag.length; i++) {
  78. showSaleprod += ftag[i] + ' ';
  79. }
  80. }*/
  81. /* 渲染数据 */
  82. this.setData({
  83. fprodname: data.fprodname, //产品名称
  84. fprodnum: data.fprodnum, //产品编码
  85. attinfos, //附件列表
  86. fintroduction: data.fintroduction, //产品说明
  87. fisonsale: data.fisonsale, //是否上架
  88. //ftag: ftag, 产品标签
  89. tagents_productid: data.tagents_productid, //识别产品ID
  90. showSaleprod, // 显示标签
  91. checked, //是否上架
  92. fprodclassname: data.fprodclassname
  93. });
  94. };
  95. },
  96. /* 回调 */
  97. optionChangeCallBack(e) {
  98. this.setData({
  99. fprodclassname: e.detail,
  100. pupShow: false,
  101. "errTips.fprodclassname": false
  102. })
  103. },
  104. /**
  105. * 生命周期函数--监听页面初次渲染完成
  106. */
  107. onReady: function () {
  108. },
  109. /* 添加图片 */
  110. imageChange(data) {
  111. this.setData({
  112. attinfos: data.detail.fileList
  113. })
  114. },
  115. /* 上架开关 */
  116. switchChange() {
  117. const that = this;
  118. wx.showModal({
  119. title: "提示",
  120. content: (this.data.checked) ? '是否确认下架该产品' : '是否确认上架该产品',
  121. success(res) {
  122. if (res.confirm) {
  123. const checked = !that.data.checked,
  124. fisonsale = (checked) ? 1 : 0;
  125. that.setData({
  126. checked,
  127. fisonsale
  128. });
  129. }
  130. }
  131. })
  132. },
  133. /* 表单验证 */
  134. formVerify() {
  135. let errTips = this.data.errTips,
  136. verify = true;
  137. /* 验证产品名称 */
  138. if (!_Verify.required(this.data.fprodname)) {
  139. errTips.fprodname = true;
  140. verify = false;
  141. }
  142. /* 验证产品编码 */
  143. if (!_Verify.required(this.data.fprodnum)) {
  144. errTips.fprodnum = true;
  145. verify = false;
  146. }
  147. /* 验证产品分类 */
  148. if (!_Verify.required(this.data.fprodclassname)) {
  149. errTips.fprodclassname = true;
  150. verify = false;
  151. }
  152. /* 验证附件列表 */
  153. if (!_Verify.required(this.data.attinfos, "请上传产品图片")) {
  154. verify = false;
  155. }
  156. this.setData({
  157. errTips
  158. })
  159. return verify;
  160. },
  161. /* 提交 */
  162. submit() {
  163. if (!this.formVerify() || this.data.throttle) return;
  164. //请求参数
  165. _Http.basic({
  166. "accesstoken": wx.getStorageSync('userData').token,
  167. "classname": "customer.products.products",
  168. "method": "insertOrModifyProducts",
  169. "content": {
  170. "tagents_productid": this.data.tagents_productid,
  171. "fprodnum": this.data.fprodnum,
  172. "fprodname": this.data.fprodname,
  173. "fintroduction": this.data.fintroduction,
  174. "fisonsale": this.data.fisonsale,
  175. "fprodclassname": this.data.fprodclassname
  176. }
  177. }).then(res => {
  178. console.log(res)
  179. if (res.msg != "成功") return wx.showToast({
  180. title: res.data,
  181. icon: "none"
  182. });
  183. this.setData({
  184. throttle: true //设置节流阀
  185. });
  186. let content = {
  187. ownerid: res.data[0].tagents_productid,
  188. ownertable: "tagents_product",
  189. tattachmentid: 0
  190. };
  191. this.selectComponent("#UploadFiles").saveTheChanges(content);
  192. wx.showToast({
  193. title: '保存成功',
  194. })
  195. setTimeout(() => {
  196. wx.navigateBack({
  197. delta: 1,
  198. })
  199. }, 500)
  200. })
  201. },
  202. /* 获取焦点 */
  203. inputFocus(e) {
  204. const {
  205. name
  206. } = e.currentTarget.dataset;
  207. let errTips = this.data.errTips;
  208. errTips[name] = false;
  209. /* 经营类目提示框 */
  210. if (name == 'showSaleprod') {
  211. errTips[name] = true;
  212. }
  213. this.setData({
  214. errTips
  215. })
  216. },
  217. /* 失去焦点 */
  218. inputBlur(e) {
  219. const {
  220. name
  221. } = e.currentTarget.dataset;
  222. const {
  223. value
  224. } = e.detail;
  225. let errTips = this.data.errTips;
  226. if (value.trim() == "") errTips[name] = true;
  227. /* 经营类目提示框,字符串转化数组 */
  228. if (name == 'showSaleprod') {
  229. errTips[name] = false;
  230. const ftag = this.data.showSaleprod.split(" ");
  231. this.setData({
  232. ftag
  233. })
  234. };
  235. this.setData({
  236. errTips
  237. })
  238. },
  239. /**
  240. * 生命周期函数--监听页面显示
  241. */
  242. onShow: function () {
  243. },
  244. /**
  245. * 生命周期函数--监听页面隐藏
  246. */
  247. onHide: function () {
  248. },
  249. /**
  250. * 生命周期函数--监听页面卸载
  251. */
  252. onUnload: function () {},
  253. /**
  254. * 页面相关事件处理函数--监听用户下拉动作
  255. */
  256. onPullDownRefresh: function () {
  257. },
  258. /**
  259. * 页面上拉触底事件的处理函数
  260. */
  261. onReachBottom: function () {
  262. },
  263. /**
  264. * 用户点击右上角分享
  265. */
  266. onShareAppMessage: function () {
  267. }
  268. })