settledStore.js 6.6 KB

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