<template>
  <div style="width:900px">
    <div>
      <p>已选中批量修改记录数：{{ idArray.length }}行</p>
      <div style="margin: 10px 0;border: 1px solid #eee;padding: 16px;">
        <Form
          ref="formModel"
          :model="formModel"
          :label-width="120"
          inline
        >
          <FormItem
            label="店铺仓库供货比例:"
            prop="percent"
          >
            <Input
              v-model="formModel.percent"
              placeholder="请输入店铺仓库供货比例"
              type="text"
              :regx="regx"
              class="percentNumber"
              maxlength="3"
            /></Input>
          </FormItem>
          <FormItem
            label="缺货默认逻辑仓:"
          >
            <Select v-model="formModel.ISDEFAULTLACKSTORE" style="width:200px">
              <Option value="1" >是</Option>
              <Option value="0" >否</Option>
            </Select>
          </FormItem>
        </Form>
      </div>
    </div>
    <div
      class="pop-btn"
      style="display:flex;justify-content: flex-end;"
    >
      <Button
        type="fcdefault"
        class="sav-btn"
        @click="toBatchAudit"
      >
        确定
      </Button>
      <Button
        class="cancel-btn"
        style="margin-left:8px"
        @click="close"
      >
        取消
      </Button>
    </div>
  </div>
</template>
<script>
  const R3 = window.R3;
  const { network, urlSearchParams, store } = R3;
  export default {
    props: {
      idArray: { // 获取ID用于多选
        type: Array,
        default: () => []
      },
      selectRowData: { // 获取选择行的数据
        type: Array,
        default: () => []
      }
    },
    data() {
      return {
        regx: /^[0-9]*$/,
        formModel: {
          percent: '',
          ISDEFAULTLACKSTORE: '',
        }
      };
    },
    methods: {
      toBatchAudit() {
        if (!this.formModel.percent && !this.formModel.ISDEFAULTLACKSTORE) {
          return this.$Message.warning('没有数据更新，请确认！');
        }
        let data = {
          fixedData: { STOCKSCALE: this.formModel.percent, ISDEFAULTLACKSTORE: this.formModel.ISDEFAULTLACKSTORE},
          searchdata: { 
            table: 'T_V_IESSHOPSTORE', 
            column_include_uicontroller: true, 
            reffixedcolumns: {}, 
            objids: this.idArray
          }
        };
        network.post('/p/cs/batchSave', data).then((res) => {
          if (res.data.code == 0) {
            this.$Message.success('修改比例设置后不会自动同步库存至平台，请至【平台商品管理】中根据选择条件手动同步库存');
            const { fullPath } = this.$route;
            let index = fullPath.lastIndexOf('/');
            let tableId = fullPath.slice(index + 1, fullPath.length);
            const {
              keepAliveModuleName, tableName
            } = this.$store.state.global.activeTab;
            this.$store.commit('global/tabCloseAppoint', {
              tableName,
              routeFullPath: fullPath,
              keepAliveModuleName,
            });
            // 跳转
            this.$store.commit('global/tabOpen', {
              type: 'S',
              tableName,
              tableId,
              back: true
            });
            // 成功关闭弹框
            this.$emit('cancel');
          } else {
            this.$Message.error('批量修改店铺仓库供货比例失败');
          }
        });
      },
      close() {
        // 成功关闭弹框
        this.$emit('cancel');
      }
    }
    
  };
</script>
<style lang="less">
  .percentNumber .ark-input {
    width: 170px;
  }
</style>
