offer.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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.name }}</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.num" :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. },
  58. computed: {
  59. // 合计费用
  60. countMoney() {
  61. let countMoney = 0
  62. this.goodList.forEach((ele) => {
  63. countMoney += Number(ele.num) * Number(ele.price)
  64. })
  65. if (countMoney) {
  66. return countMoney
  67. } else {
  68. return 0
  69. }
  70. }
  71. },
  72. onLoad(options) {
  73. // console.log(options)
  74. let info = JSON.parse(decodeURIComponent(options.info))
  75. this.worker = info.workerName
  76. this.phone = info.workerPhone
  77. if (options.type) {
  78. console.log('改价')
  79. this.goodList = info.goodsList
  80. uni.setNavigationBarTitle({
  81. title: '改价'
  82. })
  83. }
  84. uni.$on('addConsumable', this.addConsumable)
  85. },
  86. methods: {
  87. // 单价输入框输入回调
  88. handleChangePrice(e, item) {
  89. // 验证输入单价格式 只能是数字,小数点最多两位
  90. const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
  91. if (!reg.test(e.detail.value)) {
  92. uni.showToast({
  93. title: '请确定单价为数字,并且只能保留两位小数点',
  94. icon: 'none'
  95. })
  96. item.price = 0
  97. }
  98. },
  99. // 确认提交按钮回调
  100. handleSub() {
  101. if (!this.goodList.length) {
  102. uni.showToast({
  103. title: '请添加耗材',
  104. icon: 'none'
  105. })
  106. return
  107. }
  108. if (this.countMoney <= 0) {
  109. uni.showToast({
  110. title: '合计费用不能小于0元',
  111. icon: 'none'
  112. })
  113. return
  114. }
  115. uni.showModal({
  116. title: '提示',
  117. content: '确认提交吗?',
  118. success: (res) => {
  119. if (res.confirm) {
  120. uni.showToast({
  121. title: '提交成功',
  122. icon: 'success'
  123. })
  124. setTimeout(() => {
  125. uni.reLaunch({
  126. url: '/pagesRepairs/box/box'
  127. })
  128. }, 1500)
  129. console.log(this.goodList)
  130. console.log(this.countMoney)
  131. console.log(this.worker)
  132. console.log(this.phone)
  133. }
  134. }
  135. })
  136. },
  137. // 全局自定义事件
  138. addConsumable(e) {
  139. // console.log(e)
  140. // 判断是否存在相同的耗材
  141. let flag = this.goodList.some((ele) => {
  142. return ele.name === e.data
  143. })
  144. if (!flag) {
  145. this.goodList.push({
  146. name: e.data,
  147. num: 1,
  148. price: ''
  149. })
  150. }
  151. },
  152. // 耗材数量计数器改变回调
  153. bindChange(e, index) {
  154. // console.log(e)
  155. // console.log(index)
  156. if (e === 0) {
  157. this.goodList.splice(index, 1)
  158. }
  159. },
  160. // 添加耗材按钮回调
  161. handleAdd() {
  162. uni.navigateTo({
  163. url: '/pagesRepairs/addGoods/addGoods'
  164. })
  165. }
  166. }
  167. }
  168. </script>
  169. <style lang="scss" scoped>
  170. .container {
  171. box-sizing: border-box;
  172. padding: 0 30rpx;
  173. width: 100vw;
  174. height: 100vh;
  175. overflow-y: auto;
  176. .title {
  177. height: 109rpx;
  178. line-height: 109rpx;
  179. font-size: 36rpx;
  180. font-weight: bold;
  181. }
  182. .detail_box {
  183. box-sizing: border-box;
  184. margin-bottom: 46rpx;
  185. padding: 5rpx 30rpx 0;
  186. width: 690rpx;
  187. height: 284rpx;
  188. border-radius: 9rpx;
  189. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
  190. .detail_box_item {
  191. display: flex;
  192. justify-content: space-between;
  193. align-items: center;
  194. height: 92rpx;
  195. font-size: 32rpx;
  196. border-bottom: 1rpx solid #e5e5e5;
  197. .item_key {
  198. width: 150rpx;
  199. color: #808080;
  200. }
  201. .item_value {
  202. font-weight: bold;
  203. input {
  204. text-align: right;
  205. }
  206. }
  207. }
  208. }
  209. .add {
  210. display: flex;
  211. justify-content: center;
  212. align-items: center;
  213. width: 690rpx;
  214. height: 90rpx;
  215. color: #6fb6b8;
  216. font-size: 32rpx;
  217. border-radius: 9rpx;
  218. background-color: #ebf2f2;
  219. text {
  220. margin-right: 10rpx;
  221. font-size: 48rpx;
  222. }
  223. }
  224. .total {
  225. display: flex;
  226. justify-content: space-between;
  227. align-items: center;
  228. margin: auto;
  229. width: 622rpx;
  230. height: 100rpx;
  231. font-size: 32rpx;
  232. font-weight: bold;
  233. border-bottom: 1rpx solid #e5e5e5;
  234. }
  235. .box {
  236. display: flex;
  237. align-items: center;
  238. height: 94rpx;
  239. font-size: 32rpx;
  240. border-radius: 10rpx;
  241. border: 1rpx solid #cccccc;
  242. img {
  243. margin: 0 14rpx 0 30rpx;
  244. width: 40rpx;
  245. height: 40rpx;
  246. }
  247. }
  248. .title2 {
  249. height: 126rpx;
  250. line-height: 126rpx;
  251. font-size: 36rpx;
  252. font-weight: bold;
  253. }
  254. .btn {
  255. display: flex;
  256. justify-content: center;
  257. align-items: center;
  258. margin: 194rpx 0 60rpx;
  259. height: 100rpx;
  260. color: #fff;
  261. font-size: 32rpx;
  262. border-radius: 12rpx;
  263. background-color: #6fb6b8;
  264. }
  265. }
  266. </style>