updatePayment.vue 8.5 KB

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