schemeAdd.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <view class="mainBox">
  3. <uni-nav-bar background-color="#157A2C" color="#fff" fixed="true" statusBar="true" left-icon="back" title="方案信息"
  4. @clickLeft="back">
  5. </uni-nav-bar>
  6. <u-cell-group>
  7. <u-cell title="项目" arrow-direction="down">
  8. <uni-data-picker v-model="form.typeId" slot="value" :clear-icon='false' placeholder="请选择"
  9. :localdata="typeIdList" @change="typeOnchange">
  10. </uni-data-picker>
  11. </u-cell>
  12. <u-cell title="编码" arrow-direction="down">
  13. <u--input v-if="form.typeId != '2'" slot="value" placeholder="请输入" border="surround"
  14. v-model="form.code">
  15. </u--input>
  16. <view class="labels" slot="value" v-if="form.typeId == '2'">
  17. {{ form.code }}
  18. </view>
  19. </u-cell>
  20. <u-cell title="名称" arrow-direction="down">
  21. <u--input v-if="form.typeId == '2'" @click.native="selectProduct" slot="value" placeholder="请选择"
  22. border="surround" v-model="form.name">
  23. </u--input>
  24. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  25. v-model="form.name"></u--input>
  26. </u-cell>
  27. <u-cell title="型号" arrow-direction="down">
  28. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  29. v-model="form.categoryModel"></u--input>
  30. <view class="labels" slot="value" v-if="form.typeId == '2'">
  31. {{ form.categoryModel }}
  32. </view>
  33. </u-cell>
  34. <u-cell title="规格" arrow-direction="down">
  35. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  36. v-model="form.specification"></u--input>
  37. <view class="labels" slot="value" v-if="form.typeId == '2'">
  38. {{ form.specification }}
  39. </view>
  40. </u-cell>
  41. <u-cell title="仓库" arrow-direction="down">
  42. <template v-if="obtain == '主数据'">
  43. <!-- <uni-data-picker v-if="form.typeId != '2'" v-model="form.warehouseId" slot="value"
  44. :clear-icon='false' placeholder="请选择" :localdata="warehouseList" @change="warehouseOnchange">
  45. </uni-data-picker> -->
  46. <uni-data-select v-if="form.typeId == '2'" slot="value" v-model="form.warehouseId"
  47. @change="warehouseOnchange" :clear="false" :localdata="warehouseList">
  48. </uni-data-select>
  49. <u--input v-if="form.typeId != '2'" slot="value" placeholder="请输入" border="surround"
  50. v-model="form.warehouseName" disabled></u--input>
  51. </template>
  52. <template v-else>
  53. <u--input slot="value" placeholder="请输入仓库" border="surround" v-model="form.warehouseName"
  54. disabled></u--input>
  55. </template>
  56. </u-cell>
  57. <u-cell title="库存" arrow-direction="down">
  58. <!-- <u--input slot="value" placeholder="请输入" border="surround" v-model="form.warehouseNum"></u--input> -->
  59. <view class="labels" slot="value">
  60. {{ form.warehouseNum }}
  61. </view>
  62. </u-cell>
  63. <u-cell title="单位" arrow-direction="down">
  64. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  65. v-model="form.measureUnit"></u--input>
  66. <view class="labels" slot="value" v-if="form.typeId == '2'">
  67. {{ form.measureUnit }}
  68. </view>
  69. </u-cell>
  70. <u-cell title="数量" arrow-direction="down">
  71. <u--input slot="value" type="number" @input=" (val) =>inputChange(val,'totalCount')" placeholder="请输入"
  72. border="surround" v-model="form.totalCount"></u--input>
  73. </u-cell>
  74. <u-cell title="单价" arrow-direction="down">
  75. <u--input type="number" slot="value" @input="(val) =>inputChange(val,'singlePrice')" placeholder="请输入"
  76. border="surround" v-model="form.singlePrice"></u--input>
  77. </u-cell>
  78. <u-cell title="合计" arrow-direction="down">
  79. <view class="labels" slot="value">
  80. {{ form.settlementPrice }}
  81. </view>
  82. </u-cell>
  83. <u-cell title="详细内容" arrow-direction="down">
  84. <u--input slot="value" placeholder="请输入" border="surround" v-model="form.content"></u--input>
  85. </u-cell>
  86. <view class="footerButton">
  87. <u-button type="default" text="返回" @click="back"></u-button>
  88. <u-button type="primary" @click="save" text="保存"></u-button>
  89. </view>
  90. </u-cell-group>
  91. <u-toast ref="uToast"></u-toast>
  92. </view>
  93. </template>
  94. <script>
  95. import {
  96. getIdWarehouseList
  97. } from '@/api/salesServiceManagement/workOrder/index.js'
  98. export default {
  99. data() {
  100. return {
  101. form: {
  102. typeId: '2',
  103. code: '',
  104. name: '',
  105. categoryModel: '', // 型号
  106. specification: '', // 规格
  107. content: '', // 详细内容
  108. warehouseId: '', // 仓库id\
  109. warehouseNum: '', // 库存
  110. totalCount: '', // 数量
  111. measureUnit: '', // 单位
  112. singlePrice: '', // 单价
  113. settlementPrice: '', // 合计
  114. },
  115. typeIdList: [{
  116. text: '工时',
  117. value: '1'
  118. },
  119. {
  120. text: '零配件',
  121. value: '2'
  122. },
  123. {
  124. text: '差旅费',
  125. value: '3'
  126. }
  127. ],
  128. obtain: '主数据',
  129. warehouseList: [], // 仓库数据
  130. oldTypeId: '2', // 旧的项目选择
  131. }
  132. },
  133. onLoad(params) {
  134. let data = JSON.parse(params.data);
  135. if (data.code) {
  136. this.form = data;
  137. }
  138. console.log(data, 'params')
  139. this.obtain = params.obtain || '主数据'
  140. },
  141. created() {
  142. uni.$off('updateScheme');
  143. uni.$on('updateScheme', async (data) => {
  144. this.form = {
  145. ...this.form,
  146. ...data
  147. };
  148. console.log(this.form, 'data ----')
  149. if (this.obtain == '主数据') {
  150. const res = await getIdWarehouseList({
  151. categoryId: ''
  152. })
  153. res && res.map((el) => {
  154. el.text = el.warehouseName;
  155. el.value = el.warehouseId;
  156. })
  157. this.warehouseList = res || [];
  158. }
  159. })
  160. },
  161. methods: {
  162. // 如果新的选择跟旧的一样 不做数据更改
  163. typeOnchange(e) {
  164. if (this.form.typeId == this.oldTypeId) {
  165. return;
  166. }
  167. this.oldTypeId = this.form.typeId;
  168. this.form = {
  169. typeId: e.detail.value[0].text,
  170. code: '',
  171. name: '',
  172. categoryModel: '', // 型号
  173. specification: '', // 规格
  174. content: '', // 详细内容
  175. warehouseId: '', // 仓库
  176. warehouseNum: '', // 库存
  177. totalCount: '', // 数量
  178. measureUnit: '', // 单位
  179. singlePrice: '', // 单价
  180. settlementPrice: '', // 合计
  181. }
  182. },
  183. warehouseOnchange(e) {
  184. let name = this.warehouseList.find(item => item.warehouseId == e).warehouseName;
  185. this.form.warehouseName = name;
  186. },
  187. selectProduct() {
  188. uni.navigateTo({
  189. url: `/pages/salesServiceManagement/workOrder/components/selectProduct?obtain=${this.obtain}`
  190. })
  191. },
  192. save() {
  193. if (!this.form.name) {
  194. this.$refs.uToast.show({
  195. type: "warning",
  196. message: "请填写名称",
  197. })
  198. return;
  199. }
  200. uni.$emit('updateInfo', this.form);
  201. this.back();
  202. },
  203. inputChange(e, field) {
  204. // let value = e.replace(/[^\d]/g, '');
  205. // if (value.startsWith('0') && value.length > 1) {
  206. // value = value.replace(/^0+/, '');
  207. // }
  208. console.log(123)
  209. let value = '';
  210. if (field == 'singlePrice') {
  211. value = e.replace(/\./g, ''); // 如果不允许小数点,就移除所有小数点
  212. } else {
  213. value = e.replace(/[^\d]/g, '')
  214. if (value.startsWith('0') && value.length > 1) {
  215. value = value.replace(/^0+/, '');
  216. }
  217. }
  218. console.log(value, 'value')
  219. this.form[field] = value;
  220. let num1 = this.form.totalCount ? this.form.totalCount - 0 : 0;
  221. let num2 = this.form.singlePrice ? this.form.singlePrice - 0 : 0;
  222. this.form.settlementPrice = num1 * num2;
  223. },
  224. }
  225. }
  226. </script>
  227. <style scoped lang="scss">
  228. /deep/.u-cell__body__content {
  229. flex: none;
  230. margin-right: 16rpx;
  231. }
  232. .mainBox {
  233. padding-bottom: 84rpx;
  234. .labels {
  235. padding-left: 18rpx;
  236. }
  237. }
  238. .footerButton {
  239. width: 100%;
  240. height: 84rpx;
  241. display: flex;
  242. position: fixed;
  243. bottom: 0;
  244. /deep/.u-button {
  245. height: 100%;
  246. }
  247. >view {
  248. flex: 1;
  249. }
  250. }
  251. </style>