offer.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <view class="container">
  3. <view class="title">关联耗材</view>
  4. <!-- 每一个耗材盒子区域 -->
  5. <view class="detail_box" v-for="(item, index) in goodList" :key="index">
  6. <view class="detail_box_item">
  7. <view class="item_key">耗材名称</view>
  8. <view class="item_value">{{ item.consumeName }}</view>
  9. </view>
  10. <view class="detail_box_item">
  11. <view class="item_key">耗材数量</view>
  12. <view class="item_value">
  13. <uni-number-box v-model="item.number" :min="0" @change="bindChange($event, index)"></uni-number-box>
  14. </view>
  15. </view>
  16. <view class="detail_box_item">
  17. <view class="item_key">耗材单价</view>
  18. <view class="item_value">
  19. <input type="number" placeholder="请输入耗材单价" v-model="item.price" @blur="handleChangePrice($event, item)" />
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 添加耗材区域 -->
  24. <view class="add" @click="handleAdd">
  25. <text>+</text>
  26. 添加耗材
  27. </view>
  28. <!-- 合计费用区域 -->
  29. <view class="total">
  30. <view>合计费用</view>
  31. <view>{{ countMoney }}元</view>
  32. </view>
  33. <view class="title">维修师傅</view>
  34. <view class="box">
  35. <img src="../../static/images/repairsImg/people.png" />
  36. {{ worker }}
  37. </view>
  38. <view class="title2">手机</view>
  39. <view class="box">
  40. <img src="../../static/images/repairsImg/phone2.png" />
  41. {{ phone }}
  42. </view>
  43. <view class="btn" @click="handleSub">确认提交</view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. // 维修师傅
  51. worker: '',
  52. // 手机号码
  53. phone: '',
  54. // 耗材列表
  55. goodList: [],
  56. // 订单信息
  57. info: {}
  58. }
  59. },
  60. computed: {
  61. // 合计费用
  62. countMoney() {
  63. let countMoney = 0
  64. this.goodList.forEach((ele) => {
  65. countMoney += Number(ele.number) * Number(ele.price)
  66. })
  67. if (countMoney) {
  68. return countMoney
  69. } else {
  70. return 0
  71. }
  72. }
  73. },
  74. onLoad(options) {
  75. // console.log(options)
  76. this.info = JSON.parse(decodeURIComponent(options.info))
  77. // console.log(this.info)
  78. this.worker = this.info.maintenancerName
  79. this.phone = this.info.maintenancerPhone
  80. if (options.type) {
  81. console.log('改价')
  82. this.goodList = this.info.goodsList
  83. uni.setNavigationBarTitle({
  84. title: '改价'
  85. })
  86. }
  87. uni.$on('addConsumable', this.addConsumable)
  88. },
  89. onUnload() {
  90. uni.$off()
  91. },
  92. methods: {
  93. // 单价输入框输入回调
  94. handleChangePrice(e, item) {
  95. // 验证输入单价格式 只能是数字,小数点最多两位
  96. const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
  97. if (!reg.test(e.detail.value)) {
  98. uni.showToast({
  99. title: '请确定单价为数字,并且只能保留两位小数点',
  100. icon: 'none'
  101. })
  102. item.price = 0
  103. }
  104. },
  105. // 确认提交按钮回调
  106. handleSub() {
  107. if (!this.goodList.length) {
  108. uni.showToast({
  109. title: '请添加耗材',
  110. icon: 'none'
  111. })
  112. return
  113. }
  114. if (this.countMoney <= 0) {
  115. uni.showToast({
  116. title: '合计费用不能小于0元',
  117. icon: 'none'
  118. })
  119. return
  120. }
  121. uni.showModal({
  122. title: '提示',
  123. content: '确认提交吗?',
  124. success: async (res) => {
  125. if (res.confirm) {
  126. const res = await this.$myRequest_repairs({
  127. url: '/repairConsumables/insertMaintenanceConsumables',
  128. method: 'post',
  129. data: {
  130. recordId: this.info.id,
  131. totalPrice: this.countMoney,
  132. consumes: this.goodList
  133. }
  134. })
  135. // console.log(res)
  136. if (res.code === '200') {
  137. uni.showToast({
  138. title: '提交成功',
  139. icon: 'success'
  140. })
  141. setTimeout(() => {
  142. uni.reLaunch({
  143. url: '/pagesRepairs/box/box'
  144. })
  145. }, 1500)
  146. }
  147. }
  148. }
  149. })
  150. },
  151. // 全局自定义事件
  152. addConsumable(e) {
  153. console.log(e)
  154. // 判断是否存在相同的耗材
  155. let flag = this.goodList.some((ele) => {
  156. return ele.consumeName === e.data.name
  157. })
  158. if (!flag) {
  159. this.$set(e.data, 'number', 1)
  160. this.$set(e.data, 'consumeName', e.data.name)
  161. this.$set(e.data, 'consumeId', e.data.id)
  162. this.$set(e.data, 'articleId', e.articleId)
  163. // this.$delete(e.data, 'name')
  164. // this.$delete(e.data, 'id')
  165. this.goodList.push(e.data)
  166. }
  167. console.log(this.goodList)
  168. },
  169. // 耗材数量计数器改变回调
  170. bindChange(e, index) {
  171. // console.log(e)
  172. // console.log(index)
  173. if (e === 0) {
  174. this.goodList.splice(index, 1)
  175. }
  176. },
  177. // 添加耗材按钮回调
  178. handleAdd() {
  179. uni.navigateTo({
  180. url: '/pagesRepairs/addGoods/addGoods'
  181. })
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. .container {
  188. box-sizing: border-box;
  189. padding: 0 30rpx;
  190. width: 100vw;
  191. height: 100vh;
  192. overflow-y: auto;
  193. .title {
  194. height: 109rpx;
  195. line-height: 109rpx;
  196. font-size: 36rpx;
  197. font-weight: bold;
  198. }
  199. .detail_box {
  200. box-sizing: border-box;
  201. margin-bottom: 46rpx;
  202. padding: 5rpx 30rpx 0;
  203. width: 690rpx;
  204. height: 284rpx;
  205. border-radius: 9rpx;
  206. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
  207. .detail_box_item {
  208. display: flex;
  209. justify-content: space-between;
  210. align-items: center;
  211. height: 92rpx;
  212. font-size: 32rpx;
  213. border-bottom: 1rpx solid #e5e5e5;
  214. .item_key {
  215. width: 150rpx;
  216. color: #808080;
  217. }
  218. .item_value {
  219. font-weight: bold;
  220. input {
  221. text-align: right;
  222. }
  223. }
  224. }
  225. }
  226. .add {
  227. display: flex;
  228. justify-content: center;
  229. align-items: center;
  230. width: 690rpx;
  231. height: 90rpx;
  232. color: #6fb6b8;
  233. font-size: 32rpx;
  234. border-radius: 9rpx;
  235. background-color: #ebf2f2;
  236. text {
  237. margin-right: 10rpx;
  238. font-size: 48rpx;
  239. }
  240. }
  241. .total {
  242. display: flex;
  243. justify-content: space-between;
  244. align-items: center;
  245. margin: auto;
  246. width: 622rpx;
  247. height: 100rpx;
  248. font-size: 32rpx;
  249. font-weight: bold;
  250. border-bottom: 1rpx solid #e5e5e5;
  251. }
  252. .box {
  253. display: flex;
  254. align-items: center;
  255. height: 94rpx;
  256. font-size: 32rpx;
  257. border-radius: 10rpx;
  258. border: 1rpx solid #cccccc;
  259. img {
  260. margin: 0 14rpx 0 30rpx;
  261. width: 40rpx;
  262. height: 40rpx;
  263. }
  264. }
  265. .title2 {
  266. height: 126rpx;
  267. line-height: 126rpx;
  268. font-size: 36rpx;
  269. font-weight: bold;
  270. }
  271. .btn {
  272. display: flex;
  273. justify-content: center;
  274. align-items: center;
  275. margin: 194rpx 0 60rpx;
  276. height: 100rpx;
  277. color: #fff;
  278. font-size: 32rpx;
  279. border-radius: 12rpx;
  280. background-color: #6fb6b8;
  281. }
  282. }
  283. </style>