editShelfHw.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view class="content flex flex_column">
  3. <view class="form-body">
  4. <u-form :model="form" label-width="180rpx" :error-type="['toast']" ref="uForm">
  5. <u-form-item label="货位号">
  6. <view class="flex align_center flex_1 justify_between">
  7. <view style="width: 80%;">{{shelfPlaceCode}}</view>
  8. <view style="width: 20%;text-align: center;" @click="editShelf"><u-icon name='edit-pen'></u-icon>修改</view>
  9. </view>
  10. </u-form-item>
  11. <view v-if="productEntity">
  12. <u-form-item label="" prop="productSn">
  13. <view class="flex flex_1">
  14. <view class="pimgs">
  15. <u-image :src="productEntity.productMsg?productEntity.productMsg:`../../static/${$config('themePath')}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
  16. </view>
  17. <view class="pinfo flex_1">
  18. <view class="ptxt flex align_center justify_between">
  19. <text>{{productEntity.code}}</text>
  20. <text class="pcode" @click="toBindProduct">
  21. <u-icon name='reload'></u-icon>
  22. 更换产品
  23. </text>
  24. </view>
  25. <view class="pname">
  26. {{productEntity.name}}
  27. </view>
  28. </view>
  29. </view>
  30. </u-form-item>
  31. <u-form-item label="销售价(元)" required prop="price">
  32. <u-input clearable type="number" :min="0" @input="numberToFixed('price',2,999999)" v-model="form.price" placeholder="请输入销售价,最多两位小数"/>
  33. </u-form-item>
  34. <u-form-item label="结算价(元)" required prop="cost">
  35. <u-input clearable type="number" :min="0" @input="numberToFixed('cost',2,999999)" v-model="form.cost" placeholder="请输入结算价,最多两位小数"/>
  36. </u-form-item>
  37. <u-form-item label="最大库容(件)" required prop="maxQty">
  38. <u-number-box :min="0" :max="999999" positive-integer v-model="form.maxQty" color="#000" bg-color="#fff" size="30" :input-height="70" :input-width="150"></u-number-box>
  39. </u-form-item>
  40. </view>
  41. <view class="noproduct" v-else @click="toBindProduct">
  42. <view>
  43. <u-empty :src="`/static/${$config('themePath')}/def_no_data@3x.png`" icon-size="150" text="此货位还未绑定产品" mode="list"></u-empty>
  44. </view>
  45. <view>点击去 <text>绑定产品</text></view>
  46. </view>
  47. </u-form>
  48. </view>
  49. <view class="flex footer-btn">
  50. <u-button v-if="type=='bind'" class="delbtn" :loading='loading' @click="handleDel" type='primary' shape="circle" size="medium">删除货位</u-button>
  51. <u-button :style="{width:type=='bind'?'45%':'100%'}" class="newbtn" :loading='loading' @click="formSubmit" type='primary' shape="circle" size="medium">保存</u-button>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import { clzConfirm, numberToFixed } from '@/libs/tools';
  57. import { shelfProductSave, shelfProductDetail, delShelfPlaceSn } from '@/api/shelf'
  58. export default {
  59. data() {
  60. return {
  61. shelfPlaceCode: '',
  62. form: {
  63. productSn: undefined,
  64. productCode: undefined,
  65. shelfProductSn: undefined,
  66. price: '', // 销售价
  67. cost: '', //结算价
  68. maxQty: 1, // 最大库容
  69. },
  70. rules: {
  71. productSn: [{ required: true, message: '请选择绑定产品', trigger: 'change' }],
  72. price: [{ required: true,type:'number', message: '请输入销售价', trigger: 'change' }],
  73. cost: [{ required: true,type:'number', message: '请输入结算价', trigger: 'change' }],
  74. maxQty: [{ required: true,type:'number', message: '请输入最大库容', trigger: 'change' }],
  75. },
  76. productEntity: null,
  77. customerSn: null,
  78. shelfPlaceSn: null,
  79. loading: false,
  80. type:"",
  81. bakProductSn: null
  82. }
  83. },
  84. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  85. onReady() {
  86. this.$refs.uForm.setRules(this.rules);
  87. },
  88. onLoad(opts) {
  89. const _this = this
  90. this.nowData = JSON.parse(decodeURIComponent(opts.detailData));
  91. this.customerSn = this.nowData.customerSn
  92. this.shelfSn = this.nowData.shelfSn
  93. this.type = opts.type
  94. this.shelfPlaceCode = this.nowData.shelfPlaceCode||''
  95. // 选在产品
  96. uni.$on('addProductToHw',function(data){
  97. console.log(data)
  98. _this.productEntity = data
  99. _this.form.price = Number(data.price)
  100. _this.form.cost = Number(data.cost)
  101. _this.form.productCode = data.code
  102. _this.form.productSn = data.productSn
  103. // 更换产品
  104. if(_this.bakProductSn != data.productSn){
  105. _this.form.updateProductFlag = 1
  106. }
  107. })
  108. // 修改货位号成功
  109. uni.$on('updateHwNo',(data)=>{
  110. this.shelfPlaceCode = data
  111. })
  112. if(this.type != 'bind'){
  113. // 获取产品信息
  114. this.getProductInfo()
  115. }
  116. },
  117. onUnload(){
  118. console.log('-----')
  119. uni.$off("addProductToHw")
  120. uni.$off("updateHwNo")
  121. },
  122. methods: {
  123. // 小数点后两位
  124. numberToFixed: function (key, num, max) {
  125. let val = this.form[key]
  126. let ret = numberToFixed(val, num, max)
  127. this.$nextTick(() => {
  128. this.form[key] = ret < 0 ? 0 : ret
  129. })
  130. },
  131. // 更换产品
  132. toBindProduct(){
  133. uni.navigateTo({
  134. url: "/pages/shelfSetting/bindProduct?customerSn="+this.customerSn+"&shelfSn="+this.shelfSn
  135. })
  136. },
  137. // 编辑货位号
  138. editShelf(){
  139. const type ='edit'
  140. uni.navigateTo({
  141. url: "/pages/shelfSetting/addShelfHw?detailData="+encodeURIComponent(JSON.stringify(this.nowData))+"&type="+type+"&shelfPlaceCode="+this.shelfPlaceCode
  142. })
  143. },
  144. // 获取产品信息
  145. getProductInfo () {
  146. shelfProductDetail({ shelfPlaceSn: this.nowData && this.nowData.shelfPlaceSn }).then(res => {
  147. if (res.status == 200 && res.data) {
  148. this.productEntity = {
  149. code: res.data.productCode,
  150. name: res.data.productName,
  151. productMsg: res.data.productImageUrl
  152. }
  153. this.form.productSn = res.data.productSn
  154. this.bakProductSn = res.data.productSn
  155. this.form.productCode = res.data.productCode
  156. this.form.price = res.data.price
  157. this.form.cost = res.data.cost
  158. this.form.maxQty = res.data.maxQty
  159. } else {
  160. this.productEntity = null
  161. }
  162. })
  163. },
  164. // 删除货位
  165. handleDel (row) {
  166. const _this = this
  167. clzConfirm({
  168. title: '提示',
  169. content: '删除后无法恢复,确认删除?',
  170. success (ret) {
  171. if (ret.confirm || ret.index == 0) {
  172. _this.loading = true
  173. delShelfPlaceSn({ shelfPlaceSn: _this.nowData.shelfPlaceSn }).then(res => {
  174. if (res.status == 200) {
  175. uni.showToast({
  176. icon: "none",
  177. title: res.message
  178. })
  179. uni.$emit("updateHw")
  180. uni.navigateBack()
  181. }
  182. _this.loading = false
  183. })
  184. }
  185. }
  186. })
  187. },
  188. // 表单提交
  189. formSubmit(){
  190. const _this = this
  191. this.$refs.uForm.validate(valid => {
  192. if (valid) {
  193. const form = JSON.parse(JSON.stringify(_this.form))
  194. form.shelfPlaceSn = _this.nowData && _this.nowData.shelfPlaceSn
  195. if(this.type != 'bind'){ // 不是绑定产品
  196. form.shelfProductSn = _this.nowData && _this.nowData.shelfProductApiEntity && _this.nowData.shelfProductApiEntity.shelfProductSn || _this.nowData.shelfProductSn
  197. }
  198. // 开始提交数据
  199. _this.loading = true
  200. shelfProductSave(form).then(res => {
  201. if (res.status == 200) {
  202. uni.showToast({
  203. icon: "none",
  204. title: res.message
  205. })
  206. uni.$emit("updateHw")
  207. uni.navigateBack()
  208. }
  209. _this.loading = false
  210. })
  211. } else {
  212. console.log('验证失败');
  213. }
  214. });
  215. },
  216. }
  217. }
  218. </script>
  219. <style lang="less">
  220. .content{
  221. height: 100vh;
  222. width: 100%;
  223. .form-body{
  224. flex-grow: 1;
  225. > view{
  226. background-color: #fff;
  227. padding: 0 1.5rem;
  228. }
  229. .pimgs{
  230. padding:0.1rem;
  231. background:#f8f8f8;
  232. border-radius:0.3rem;
  233. }
  234. .pinfo{
  235. line-height:normal;
  236. padding-left: 20rpx;
  237. color: #666;
  238. .ptxt{
  239. padding-bottom:20rpx;
  240. }
  241. .pcode{
  242. color:rgb(0, 170, 255);
  243. }
  244. .pname{
  245. font-weight: bold;
  246. }
  247. }
  248. .noproduct{
  249. padding: 40rpx 20rpx;
  250. text-align: center;
  251. color: #999;
  252. >view{
  253. padding: 10rpx 0;
  254. }
  255. text{
  256. color: #00aaff;
  257. margin-left: 10rpx;
  258. }
  259. }
  260. }
  261. .footer-btn{
  262. padding: 0.5rem 2rem;
  263. justify-content: space-between;
  264. button{
  265. min-width: 45%;
  266. }
  267. .newbtn{
  268. background-color: rgb(51, 95, 182);
  269. color: #fff;
  270. }
  271. .delbtn{
  272. background-color: #fff;
  273. color: red;
  274. }
  275. }
  276. }
  277. </style>