| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- <template>
- <view class="container">
- <view class="title">关联耗材</view>
- <!-- 每一个耗材盒子区域 -->
- <view class="detail_box" v-for="(item, index) in goodList" :key="index">
- <view class="detail_box_item">
- <view class="item_key">耗材名称</view>
- <view class="item_value">{{ item.name }}</view>
- </view>
- <view class="detail_box_item">
- <view class="item_key">耗材数量</view>
- <view class="item_value">
- <uni-number-box v-model="item.num" :min="0" @change="bindChange($event, index)"></uni-number-box>
- </view>
- </view>
- <view class="detail_box_item">
- <view class="item_key">耗材单价</view>
- <view class="item_value">
- <input type="number" placeholder="请输入耗材单价" v-model="item.price" @blur="handleChangePrice($event, item)" />
- </view>
- </view>
- </view>
- <!-- 添加耗材区域 -->
- <view class="add" @click="handleAdd">
- <text>+</text>
- 添加耗材
- </view>
- <!-- 合计费用区域 -->
- <view class="total">
- <view>合计费用</view>
- <view>{{ countMoney }}元</view>
- </view>
- <view class="title">维修师傅</view>
- <view class="box">
- <img src="../../static/images/repairsImg/people.png" />
- {{ worker }}
- </view>
- <view class="title2">手机</view>
- <view class="box">
- <img src="../../static/images/repairsImg/phone2.png" />
- {{ phone }}
- </view>
- <view class="btn" @click="handleSub">确认提交</view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- // 维修师傅
- worker: '张三',
- // 手机号码
- phone: '13659854589',
- // 耗材列表
- goodList: []
- }
- },
- computed: {
- // 合计费用
- countMoney() {
- let countMoney = 0
- this.goodList.forEach((ele) => {
- countMoney += Number(ele.num) * Number(ele.price)
- })
- if (countMoney) {
- return countMoney
- } else {
- return 0
- }
- }
- },
- onLoad() {
- uni.$on('addConsumable', this.addConsumable)
- },
- methods: {
- // 单价输入框输入回调
- handleChangePrice(e, item) {
- // 验证输入单价格式 只能是数字,小数点最多两位
- const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
- if (!reg.test(e.detail.value)) {
- uni.showToast({
- title: '请确定单价为数字,并且只能保留两位小数点',
- icon: 'none'
- })
- item.price = 0
- }
- },
- // 确认提交按钮回调
- handleSub() {
- if (!this.goodList.length) {
- uni.showToast({
- title: '请添加耗材',
- icon: 'none'
- })
- return
- }
- if (this.countMoney <= 0) {
- uni.showToast({
- title: '合计费用不能小于0元',
- icon: 'none'
- })
- return
- }
- uni.showToast({
- title: '报价成功',
- icon: 'success'
- })
- setTimeout(() => {
- uni.reLaunch({
- url: '/pagesRepairs/box/box'
- })
- }, 1500)
- console.log(this.goodList)
- console.log(this.countMoney)
- console.log(this.worker)
- console.log(this.phone)
- },
- // 全局自定义事件
- addConsumable(e) {
- // console.log(e)
- // 判断是否存在相同的耗材
- let flag = this.goodList.some((ele) => {
- return ele.name === e.data
- })
- if (!flag) {
- this.goodList.push({
- name: e.data,
- num: 1,
- price: 0
- })
- }
- },
- // 耗材数量计数器改变回调
- bindChange(e, index) {
- // console.log(e)
- // console.log(index)
- if (e === 0) {
- this.goodList.splice(index, 1)
- }
- },
- // 添加耗材按钮回调
- handleAdd() {
- uni.navigateTo({
- url: '/pagesRepairs/addGoods/addGoods'
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .container {
- box-sizing: border-box;
- padding: 0 30rpx;
- width: 100vw;
- height: 100vh;
- overflow-y: auto;
- .title {
- height: 109rpx;
- line-height: 109rpx;
- font-size: 36rpx;
- font-weight: bold;
- }
- .detail_box {
- box-sizing: border-box;
- margin-bottom: 46rpx;
- padding: 5rpx 30rpx 0;
- width: 690rpx;
- height: 284rpx;
- border-radius: 9rpx;
- box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
- .detail_box_item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- height: 92rpx;
- font-size: 32rpx;
- border-bottom: 1rpx solid #e5e5e5;
- .item_key {
- width: 150rpx;
- color: #808080;
- }
- .item_value {
- font-weight: bold;
- input {
- text-align: right;
- }
- }
- }
- }
- .add {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 690rpx;
- height: 90rpx;
- color: #6fb6b8;
- font-size: 32rpx;
- border-radius: 9rpx;
- background-color: #ebf2f2;
- text {
- margin-right: 10rpx;
- font-size: 48rpx;
- }
- }
- .total {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin: auto;
- width: 622rpx;
- height: 100rpx;
- font-size: 32rpx;
- font-weight: bold;
- border-bottom: 1rpx solid #e5e5e5;
- }
- .box {
- display: flex;
- align-items: center;
- height: 94rpx;
- font-size: 32rpx;
- border-radius: 10rpx;
- border: 1rpx solid #cccccc;
- img {
- margin: 0 14rpx 0 30rpx;
- width: 40rpx;
- height: 40rpx;
- }
- }
- .title2 {
- height: 126rpx;
- line-height: 126rpx;
- font-size: 36rpx;
- font-weight: bold;
- }
- .btn {
- display: flex;
- justify-content: center;
- align-items: center;
- margin: 194rpx 0 60rpx;
- height: 100rpx;
- color: #fff;
- font-size: 32rpx;
- border-radius: 12rpx;
- background-color: #6fb6b8;
- }
- }
- </style>
|