updatePayment.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view>
  3. <view class="search">
  4. <view class="search-title">
  5. {{$t('dosugar.equipmentClientID')}}
  6. </view>
  7. <view class="search-input">
  8. <input type="text" :placeholder="$t('dosugar.placeholder')" v-model="searchClientId" />
  9. </view>
  10. <view class="search-button">
  11. <button type="primary" size="mini" class="" @click="search()">
  12. <p class="">{{$t('dosugar.search')}}</P>
  13. </button>
  14. </view>
  15. </view>
  16. <view class="td-right">
  17. <view class="uni-list">
  18. <view class="uni-list-cell">
  19. <view class="uni-list-cell-left">
  20. {{$t('dosugar.chooseEquipment')}}
  21. </view>
  22. <view class="uni-list-cell-db" style="overflow: hidden;text-overflow: ellipsis;">
  23. <picker @change="changeEquipment" :value="index" :range="equipmentNameList">
  24. <view class="uni-input">{{equipmentNameList[index]}}</view>
  25. </picker>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="line"></view>
  31. <view class="paymentType" v-for="(item,index) in payments" :key="index">
  32. <P class="paymentTypeName">{{item.value}}: </P>
  33. <radio-group @change="changeShow(item.key, $event)">
  34. <label>
  35. <radio :checked='item.status== 1' :value="onStatus.toString()">{{$t('payment.on')}}</radio>
  36. </label>
  37. <label>
  38. <radio :checked='item.status==null || item.status==0' :value="offStatus.toString()">
  39. {{$t('payment.off')}}
  40. </radio>
  41. </label>
  42. </radio-group>
  43. </view>
  44. <view class="tr">
  45. <button type="primary" formType="submit" @click="updatePaymentType()" class="button">
  46. {{$t('flowers.submit')}}
  47. </button>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import {
  53. mapState,
  54. mapActions,
  55. mapMutations
  56. } from 'vuex'
  57. export default {
  58. data() {
  59. return {
  60. globalUser: {},
  61. index: null,
  62. index2: null,
  63. equipmentName: null,
  64. equipmentNameList: [],
  65. // Nayax信用卡器支付、WMDB信用卡支付以及混合支付
  66. payments: [],
  67. paymentList: [], //支付方式数组
  68. paymentType: null, //支付方式提交数据
  69. productName: null,
  70. equipmentId: null,
  71. searchClientId: null,
  72. showType: 0,
  73. defaultPayment: [{
  74. key: 'Z1',
  75. value: 'Nayax payment',
  76. status: 0
  77. },
  78. {
  79. key: 'Z2',
  80. value: 'WMDB payment',
  81. status: 0
  82. },
  83. {
  84. key: 'Z3',
  85. value: 'Mixed payment',
  86. status: 0
  87. },
  88. ], //默认支付方式列表
  89. onStatus: 1,
  90. offStatus: 0,
  91. }
  92. },
  93. onShow() {
  94. this.globalUser = uni.getStorageSync("globalUser");
  95. var token = uni.getStorageSync("token");
  96. uni.setNavigationBarTitle({
  97. title: this.$t('remoteList.payment')
  98. });
  99. if (token.length > 1) {
  100. this.getEquipmentListData();
  101. } else {
  102. uni.reLaunch({
  103. url: '../Login/Login',
  104. });
  105. }
  106. },
  107. methods: {
  108. ...mapActions('chart', ['getEquipmentListByUser']),
  109. getEquipmentListData() {
  110. this.getEquipmentListByUser(this.globalUser)
  111. .then(data => {
  112. this.merchantList = data;
  113. var listName = data[0].equipmentList;
  114. var equipmentNameList = [];
  115. for (var i = 0; i < listName.length; i++) {
  116. equipmentNameList.push(this.$t('common.name') + listName[i].name + ' , '+ this.$t('common.ID') + listName[i].clientId.substring(
  117. listName[i].clientId.length - 6, listName[i].clientId.length));
  118. }
  119. this.equipmentNameList = equipmentNameList;
  120. var listId = data[0].id;
  121. if (listId != null && listId != '1') {
  122. uni.setStorageSync("listName", listName);
  123. }
  124. uni.stopPullDownRefresh();
  125. }, _ => void uni.stopPullDownRefresh());
  126. },
  127. // 根据编号搜索机器
  128. search() {
  129. var clientId = this.searchClientId;
  130. var list = uni.getStorageSync("listName");
  131. var n = 0;
  132. for (var i = 0; i < list.length; i++) {
  133. var code = list[i].clientId.substring(list[i].clientId.length - 6, list[i].clientId.length);
  134. if (code == clientId) {
  135. n++;
  136. this.index = i;
  137. console.log(this.index);
  138. var id = list[i].id;
  139. console.log(id);
  140. this.getPaymentType(this.index);
  141. this.equipmentId = id;
  142. this.productName = null;
  143. this.index2 = null;
  144. break;
  145. }
  146. }
  147. if (n == 0) {
  148. uni.showModal({
  149. title: "提示",
  150. content: "找不到该机器",
  151. success: (res) => {
  152. }
  153. })
  154. }
  155. },
  156. // 改变机器
  157. changeEquipment: function(e) {
  158. this.index = e.target.value;
  159. this.getPaymentType(this.index);
  160. this.index2 = null;
  161. this.searchClientId = null;
  162. },
  163. // 获取支付方式列表
  164. getPaymentType(index) {
  165. this.paymentType = null;
  166. this.payments = null;
  167. var list = uni.getStorageSync("listName");
  168. this.equipmentId = list[index].id;
  169. if (list[index].paymentType != null) {
  170. this.paymentType = list[index].paymentType;
  171. }
  172. if (this.paymentType == null) {
  173. this.payments = this.defaultPayment;
  174. } else {
  175. this.paymentList = new Map(this.paymentType.split(',').map(key => [key, true]));
  176. this.payments = this.defaultPayment.map(item => {
  177. if (this.paymentList.has(item.key)) {
  178. return {
  179. ...item,
  180. status: 1,
  181. };
  182. } else {
  183. return item;
  184. }
  185. });
  186. }
  187. this.paymentList = [];
  188. this.productName = null;
  189. this.paymentType = null;
  190. },
  191. // 改变支付方式
  192. changeShow(key, e) {
  193. const status = e.target.value;
  194. console.log(key, status);
  195. if (status === '1') {
  196. this.payments = this.payments.map(payment => {
  197. if (payment.key === key) {
  198. payment.status = 1;
  199. }
  200. return payment;
  201. })
  202. } else {
  203. this.payments = this.payments.map(payment => {
  204. if (payment.key === key) {
  205. payment.status = 0;
  206. }
  207. return payment;
  208. })
  209. }
  210. console.log(this.payments);
  211. },
  212. // 修改支付方式
  213. updatePaymentType() {
  214. this.paymentList = [];
  215. for (let i = 0; i < this.payments.length; i++) {
  216. const item = this.payments[i]
  217. if (item.status === 1) {
  218. this.paymentList.push(item.key);
  219. }
  220. }
  221. this.paymentType = this.paymentList.join(',')
  222. uni.showModal({
  223. title: "提示",
  224. content: "是否修改?",
  225. success: (res) => {
  226. if (res.confirm) {
  227. var token = uni.getStorageSync("token");
  228. var equipmentId = this.equipmentId;
  229. var paymentType = this.paymentType;
  230. uni.request({
  231. url: this.serverurl + '/TEquipment/updatePaymentType',
  232. data: {
  233. "id": equipmentId,
  234. "paymentType": paymentType,
  235. },
  236. header: {
  237. 'token': token
  238. },
  239. method: "POST",
  240. success: (res) => {
  241. var code = res.data.code;
  242. if (code == true) {
  243. uni.showToast({
  244. title: this.$t('payment.success'),
  245. duration: 2000
  246. });
  247. } else {
  248. uni.showToast({
  249. icon: 'error',
  250. title: res.data.message,
  251. duration: 2000
  252. });
  253. }
  254. },
  255. });
  256. } else if (res.cancel) {}
  257. }
  258. })
  259. }
  260. }
  261. }
  262. </script>
  263. <style>
  264. .search {
  265. width: 100%;
  266. padding-top: 10upx;
  267. display: flex;
  268. flex-direction: row;
  269. justify-content: flex-start;
  270. }
  271. .search-title {
  272. width: 28%;
  273. text-align: center;
  274. font-size: 26upx;
  275. font-family: "PingFang-SC-Bold";
  276. }
  277. .search-input {
  278. width: 48%;
  279. height: 25px;
  280. text-align: center;
  281. font-size: 26upx;
  282. /* font-family: "PingFang-SC-Bold"; */
  283. box-shadow: 0upx 0upx 20upx #D3D3D3;
  284. border-radius: 5upx;
  285. }
  286. .search-button {
  287. width: 20%;
  288. padding-left: 10px;
  289. padding-bottom: 5px;
  290. text-align: center;
  291. height: 60upx;
  292. text-align: left;
  293. }
  294. .tr {
  295. padding-top: 20px;
  296. display: flex;
  297. flex-direction: row;
  298. justify-content: flex-start;
  299. font-size: 48upx;
  300. font-family: "PingFang-SC-Bold";
  301. /* position: fixed; */
  302. bottom: 100upx;
  303. width: 100%;
  304. }
  305. .paymentType {
  306. font-family: "PingFang-SC-Bold";
  307. font-size: 18px;
  308. padding-top: 15upx;
  309. display: flex;
  310. flex-direction: row;
  311. justify-content: flex-start;
  312. }
  313. .paymentTypeName {
  314. width: 80%;
  315. padding-left: 40upx;
  316. padding-right: 10upx;
  317. }
  318. .button {
  319. text-align: center;
  320. width: 30%;
  321. }
  322. .p2 {
  323. font-size: 30upx;
  324. /* #ifndef H5 */
  325. padding-top: 3upx;
  326. /* #endif */
  327. position: absolute;
  328. /* 水平居中 */
  329. left: 50%;
  330. -webkit-transform: translateX(-50%);
  331. transform: translateX(-50%);
  332. }
  333. .p1 {
  334. font-size: 48upx;
  335. }
  336. .p {
  337. align: right;
  338. color: #007AFF;
  339. padding-top: 30upx;
  340. }
  341. .line {
  342. background: #ECECEC;
  343. height: 20upx;
  344. }
  345. </style>