settledStore.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. const util = require('../../utils/util.js');
  2. const form = require('../../utils/formValidation');
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userInfo: {},
  10. storeList: [],
  11. schemeList:[],
  12. deviceTypeList:[],
  13. dictList:[],
  14. agentList:[],
  15. payTypeList:[{name:'微信',value:'wx'},{name:'支付宝',value:'zfb'},{name:'现金',value:'xj'}],
  16. values: {
  17. deviceSn:'',
  18. deviceName:'',
  19. deviceLocation: '',
  20. schemeId: '',
  21. storeId: '',
  22. deviceTypeId: '',
  23. deviceBrand: '',
  24. agentId: '',
  25. payType:'wx,zfb,xj',//默认选择所有支付方式
  26. gridProductList:[]
  27. }
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. this.bindStoreList();
  34. this.bindSchemeList();
  35. this.deviceTypeList();
  36. this.getDictByCode();
  37. this.getAllAgentList();
  38. this.setData({
  39. userInfo: app.globalData.userInfo
  40. })
  41. },
  42. //商品方案列表
  43. bindSchemeList() {
  44. var that = this
  45. util.request(util.api.schemeList, {}, "GET", false, true, app.globalData.token).then((res) => {
  46. if (res.code == 200) {
  47. that.setData({
  48. schemeList: res.result
  49. })
  50. }
  51. }).catch((res) => {})
  52. },
  53. //设备类型列表
  54. deviceTypeList() {
  55. var that = this
  56. util.request(util.api.deviceTypeList, {}, "GET", false, true, app.globalData.token).then((res) => {
  57. if (res.code == 200) {
  58. that.setData({
  59. deviceTypeList: res.result
  60. })
  61. }
  62. }).catch((res) => {})
  63. },
  64. //门店列表
  65. bindStoreList() {
  66. var that = this
  67. util.request(util.api.storeList, {}, "GET", false, true,app.globalData.token).then((res) => {
  68. if (res.code == 200) {
  69. that.setData({
  70. storeList: res.result
  71. })
  72. }
  73. }).catch((res) => {})
  74. },
  75. //设备品牌
  76. getDictByCode() {
  77. var that = this
  78. util.request(util.api.getDictByCode, {code:"device_brand"}, "GET", false, true,app.globalData.token).then((res) => {
  79. if (res.code == 200) {
  80. that.setData({
  81. dictList: res.result
  82. })
  83. }
  84. }).catch((res) => {})
  85. },
  86. //代理商
  87. getAllAgentList() {
  88. var that = this
  89. util.request(util.api.allAgentList, {}, "GET", false, true,app.globalData.token).then((res) => {
  90. if (res.code == 200) {
  91. that.setData({
  92. agentList: res.result
  93. })
  94. }
  95. }).catch((res) => {})
  96. },
  97. formSubmit: function (e) {
  98. console.log(this.data.values)
  99. var that = this
  100. //表单规则
  101. let rules = [{
  102. name: "deviceSn",
  103. rule: ["required"], //可使用区间,此处主要测试功能
  104. msg: ["请输入设备编号"]
  105. }, {
  106. name: "deviceName",
  107. rule: ["required"], //可使用区间,此处主要测试功能
  108. msg: ["请输入设备名称"]
  109. }, {
  110. name: "deviceLocation",
  111. rule: ["required"],
  112. msg: ["请输入设备号"]
  113. }, {
  114. name: "schemeName",
  115. rule: ["required"],
  116. msg: ["请输入方案"]
  117. }, {
  118. name: "storeName",
  119. rule: ["required"],
  120. msg: ["请输入门店"]
  121. }, {
  122. name: "deviceTypeName",
  123. rule: ["required"],
  124. msg: ["请输入设备类型"]
  125. }, {
  126. name: "deviceBrandName",
  127. rule: ["required"],
  128. msg: ["请输入设备品牌"]
  129. }];
  130. if(this.data.userInfo.mgvmRole!=3){
  131. var agentRule = {
  132. name: "agentName",
  133. rule: ["required"],
  134. msg: ["请输入代理商"]
  135. }
  136. rules.push(agentRule)
  137. }else{
  138. this.setData({
  139. ['values.agentId']: this.data.userInfo.id,
  140. ['values.agentName']: this.data.userInfo.username,
  141. })
  142. }
  143. //进行表单检查
  144. let formData = e.detail.value;
  145. let checkRes = form.validation(formData, rules);
  146. if (!checkRes) {
  147. util.request(util.api.addDevice, that.data.values, "POST", false, true,app.globalData.token).then((res) => {
  148. if (res.code == 200) {
  149. wx.redirectTo({
  150. url: '/pages/device/index',
  151. })
  152. }else{
  153. util.toast(res.message)
  154. }
  155. }).catch((res) => {})
  156. } else {
  157. wx.showToast({
  158. title: checkRes,
  159. icon: "none"
  160. });
  161. }
  162. },
  163. formReset: function (e) {
  164. console.log("清空数据")
  165. },
  166. //选设备类型
  167. bindDeviceTypePickerChange: function (e) {
  168. var item = this.data.deviceTypeList[e.detail.value]
  169. var gridSize = item.gridSize?item.gridSize:0
  170. var gridProductList =[];
  171. for (let index = 0; index < gridSize; index++) {
  172. gridProductList.push({productGrid:index+1});
  173. }
  174. console.log(gridProductList)
  175. this.setData({
  176. ['values.deviceTypeId']: item.id,
  177. ['values.deviceTypeName']: item.deviceName,
  178. ['values.gridProductList']:gridProductList
  179. })
  180. },
  181. //选门店
  182. bindStorePickerChange: function (e) {
  183. var item = this.data.storeList[e.detail.value]
  184. this.setData({
  185. ['values.storeId']: item.id,
  186. ['values.storeName']: item.storeName
  187. })
  188. },
  189. //选方案
  190. bindSchemePickerChange: function (e) {
  191. var item = this.data.schemeList[e.detail.value]
  192. this.setData({
  193. ['values.schemeId']: item.id,
  194. ['values.schemeName']: item.schemeName
  195. })
  196. },
  197. //选设备品牌
  198. bindDictPickerChange: function (e) {
  199. var item = this.data.dictList[e.detail.value]
  200. this.setData({
  201. ['values.deviceBrand']: item.value,
  202. ['values.deviceBrandName']: item.text
  203. })
  204. },
  205. //选择代理
  206. bindAgentPickerChange: function (e) {
  207. var item = this.data.agentList[e.detail.value]
  208. this.setData({
  209. ['values.agentId']: item.id,
  210. ['values.agentName']: item.username
  211. })
  212. },
  213. //前往选择商品
  214. toSelect(e) {
  215. wx.navigateTo({
  216. url: '/pages/vendingMachine/select?index=' + e.currentTarget.dataset.index,
  217. })
  218. },
  219. //选择支付类别 数组拼装成逗号分割
  220. checkboxChange(e){
  221. console.log(e)
  222. var selectPayTypeList = e.detail.value;
  223. var payTypes = "";
  224. selectPayTypeList.forEach(payType => {
  225. payTypes+=payType+","
  226. });
  227. if(payTypes!=""){
  228. payTypes = payTypes.slice(0,payTypes.length-1);
  229. this.setData({
  230. 'values.payType': payTypes
  231. })
  232. }
  233. },
  234. number: function (e) {
  235. console.log(e)
  236. let value = this.validateNumber(e.detail.value)
  237. let inx = `values.gridProductList[${e.target.dataset.index}].${e.target.dataset.name}`
  238. this.setData({
  239. //parseInt将数字字符串转换成数字
  240. [inx]: parseInt(value)
  241. })
  242. },
  243. validateNumber(val) {
  244. //正则表达式指定字符串只能为数字
  245. return val.replace(/\D/g, '')
  246. },
  247. inputedit: function (e) {
  248. let _this = this;
  249. let dataset = e.currentTarget.dataset;
  250. let value = e.detail.value;
  251. let name = dataset.name;
  252. _this.data[name] = value;
  253. _this.setData({
  254. [name]: _this.data[name]
  255. });
  256. },
  257. })